Skip to content

Commit 606afae

Browse files
committed
第一次提交
1 parent 5ffdd3a commit 606afae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+44352
-0
lines changed

Homework Viewer.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28606.126
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework Viewer", "Homework Viewer\Homework Viewer.vcxproj", "{687BBE45-9057-420C-8418-CA09FC25F598}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{687BBE45-9057-420C-8418-CA09FC25F598}.Debug|x64.ActiveCfg = Debug|x64
17+
{687BBE45-9057-420C-8418-CA09FC25F598}.Debug|x64.Build.0 = Debug|x64
18+
{687BBE45-9057-420C-8418-CA09FC25F598}.Debug|x86.ActiveCfg = Debug|Win32
19+
{687BBE45-9057-420C-8418-CA09FC25F598}.Debug|x86.Build.0 = Debug|Win32
20+
{687BBE45-9057-420C-8418-CA09FC25F598}.Release|x64.ActiveCfg = Release|x64
21+
{687BBE45-9057-420C-8418-CA09FC25F598}.Release|x64.Build.0 = Release|x64
22+
{687BBE45-9057-420C-8418-CA09FC25F598}.Release|x86.ActiveCfg = Release|Win32
23+
{687BBE45-9057-420C-8418-CA09FC25F598}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {6A8EED13-9F7F-4648-92EB-43672CB27A15}
30+
EndGlobalSection
31+
EndGlobal

Homework Viewer/Base64.c

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#include<Windows.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
#include<tchar.h>
5+
// 全局常量定义
6+
const char * base64char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
7+
const char padding_char = '=';
8+
9+
/*编码代码
10+
* const unsigned char * sourcedata, 源数组
11+
* char * base64 ,码字保存
12+
*/
13+
int Base64EncodeA(const unsigned char * sourcedata, char * base64)
14+
{
15+
int i = 0, j = 0;
16+
unsigned char trans_index = 0; // 索引是8位,但是高两位都为0
17+
const int datalength = strlen((const char*)sourcedata);
18+
for (; i < datalength; i += 3) {
19+
// 每三个一组,进行编码
20+
// 要编码的数字的第一个
21+
trans_index = ((sourcedata[i] >> 2) & 0x3f);
22+
base64[j++] = base64char[(int)trans_index];
23+
// 第二个
24+
trans_index = ((sourcedata[i] << 4) & 0x30);
25+
if (i + 1 < datalength) {
26+
trans_index |= ((sourcedata[i + 1] >> 4) & 0x0f);
27+
base64[j++] = base64char[(int)trans_index];
28+
}
29+
else {
30+
base64[j++] = base64char[(int)trans_index];
31+
32+
base64[j++] = padding_char;
33+
34+
base64[j++] = padding_char;
35+
36+
break; // 超出总长度,可以直接break
37+
}
38+
// 第三个
39+
trans_index = ((sourcedata[i + 1] << 2) & 0x3c);
40+
if (i + 2 < datalength) { // 有的话需要编码2个
41+
trans_index |= ((sourcedata[i + 2] >> 6) & 0x03);
42+
base64[j++] = base64char[(int)trans_index];
43+
44+
trans_index = sourcedata[i + 2] & 0x3f;
45+
base64[j++] = base64char[(int)trans_index];
46+
}
47+
else {
48+
base64[j++] = base64char[(int)trans_index];
49+
50+
base64[j++] = padding_char;
51+
52+
break;
53+
}
54+
}
55+
56+
base64[j] = '\0';
57+
58+
return 0;
59+
}
60+
61+
/** 在字符串中查询特定字符位置索引
62+
* const char *str ,字符串
63+
* char c,要查找的字符
64+
*/
65+
inline int num_strchr(const char *str, char c) //
66+
{
67+
const char *pindex = strchr(str, c);
68+
if (NULL == pindex) {
69+
return -1;
70+
}
71+
return pindex - str;
72+
}
73+
/* 解码
74+
* const char * base64 码字
75+
* unsigned char * dedata, 解码恢复的数据
76+
*/
77+
int Base64DecodeA(const char * base64, unsigned char * dedata)
78+
{
79+
int i = 0, j = 0;
80+
int trans[4] = { 0,0,0,0 };
81+
for (; base64[i] != '\0'; i += 4) {
82+
// 每四个一组,译码成三个字符
83+
trans[0] = num_strchr(base64char, base64[i]);
84+
trans[1] = num_strchr(base64char, base64[i + 1]);
85+
// 1/3
86+
dedata[j++] = ((trans[0] << 2) & 0xfc) | ((trans[1] >> 4) & 0x03);
87+
88+
if (base64[i + 2] == '=') {
89+
continue;
90+
}
91+
else {
92+
trans[2] = num_strchr(base64char, base64[i + 2]);
93+
}
94+
// 2/3
95+
dedata[j++] = ((trans[1] << 4) & 0xf0) | ((trans[2] >> 2) & 0x0f);
96+
97+
if (base64[i + 3] == '=') {
98+
continue;
99+
}
100+
else {
101+
trans[3] = num_strchr(base64char, base64[i + 3]);
102+
}
103+
104+
// 3/3
105+
dedata[j++] = ((trans[2] << 6) & 0xc0) | (trans[3] & 0x3f);
106+
}
107+
108+
dedata[j] = '\0';
109+
110+
return 0;
111+
}
112+
113+
114+
115+
116+
int Base64EncodeW(WCHAR s[], WCHAR b64[])
117+
{
118+
char *cs, *cb64;
119+
int len = WideCharToMultiByte(CP_ACP, 0,s,_tcslen(s),0, 0, 0, 0);
120+
cs = malloc(len + 2);
121+
cb64 = malloc((len + 2)<<1);//够保险了
122+
WideCharToMultiByte(CP_ACP, 0, s, _tcslen(s), cs, len, 0, 0);
123+
cs[len] = 0;
124+
Base64EncodeA(cs, cb64);
125+
int lenc64= strlen(cb64);
126+
MultiByteToWideChar(CP_ACP, 0, cb64, lenc64, b64, lenc64);
127+
b64[lenc64] = '\0';
128+
free(cs);
129+
free(cb64);
130+
return 0;
131+
}
132+
133+
int Base64DecodeW(WCHAR b64[], WCHAR s[])
134+
{
135+
char *cs, *cb64;
136+
int len = WideCharToMultiByte(CP_ACP, 0, b64, _tcslen(b64), 0, 0, 0, 0);
137+
cs = malloc(len + 2);//够保险了
138+
cb64 = malloc(len + 2);
139+
WideCharToMultiByte(CP_ACP, 0, b64, len, cb64, len, 0, 0);
140+
cb64[len] = '\0';
141+
cb64[len + 1] = '\0';
142+
Base64DecodeA(cb64, cs);
143+
int lencs = strlen(cs);
144+
MultiByteToWideChar(CP_ACP, 0, cs, lencs, s, lencs);
145+
s[lencs] = '\0';
146+
free(cs);
147+
free(cb64);
148+
return 0;
149+
}

0 commit comments

Comments
 (0)