📄 code.cpp
字号:
#include <stdio.h>
#include <iostream.h>
#include <string.h>
char BASE64[64]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/'};
int main(void)
{
FILE *in, *out;
char filename[20];
cout << "Please Input the file to decode:\n ";
cin >> filename;
if ((in = fopen(filename, "rb")) == NULL){
// if ((in = fopen("e:\\cxh\\mail\\ding.wav", "rb")) == NULL){
fprintf(stderr, "Cannot open input file.\n");
return 1;
}
cout << "Please Input the file to save decoded:\n ";
cin >> filename;
if ((out = fopen(filename, "wt")) == NULL){
fprintf(stderr, "Cannot open output file.\n");
return 1;
}
unsigned long int ConvertChar=0;
unsigned long int MASK=63;
unsigned int InChar=0;
unsigned int OutChar;
unsigned long int TotalInChar = 0;
int i;
while (!feof(in)){
fgetc(in);
TotalInChar++;
}
TotalInChar-=1;;
printf("%d",TotalInChar);
rewind(in);
for(i=0;i<TotalInChar/3;i++){
InChar = fgetc(in);
ConvertChar = InChar;
InChar = fgetc(in);
ConvertChar = ConvertChar*256 + InChar;
// ConvertChar = ConvertChar << 8 + InChar;
InChar = fgetc(in);
ConvertChar = ConvertChar*256 + InChar;
// ConvertChar = ConvertChar << 8 + InChar;
OutChar = ConvertChar >> 18;
fputc(BASE64[OutChar], out);
// printf("%c/t",BASE64[OutChar]);
OutChar = (ConvertChar >> 12) & MASK;
fputc(BASE64[OutChar], out);
// printf("%c/t",BASE64[OutChar]);
OutChar = (ConvertChar >> 6) & MASK;
fputc(BASE64[OutChar], out);
// printf("%c/t",BASE64[OutChar]);
OutChar = ConvertChar & MASK;
fputc(BASE64[OutChar], out);
// printf("%c/t",BASE64[OutChar]);
/*if(i/13>0 && i%13==0){
fputc('=', out);
fputc('=', out);
fputc('=', out);
fputc('=', out);
}*/
}
if(TotalInChar%3 == 1){
InChar = fgetc(in);
ConvertChar = InChar;
ConvertChar = ConvertChar*256;
OutChar = (ConvertChar >> 6) & MASK;
fputc(BASE64[OutChar], out);
OutChar = ConvertChar & MASK;
fputc(BASE64[OutChar], out);
fputc('=', out);
fputc('=', out);
}
if(TotalInChar%3 == 2){
InChar = fgetc(in);
ConvertChar = InChar;
InChar = fgetc(in);
ConvertChar = ConvertChar*256 + InChar;
OutChar = (ConvertChar >> 12) & MASK;
fputc(BASE64[OutChar], out);
OutChar = (ConvertChar >> 6) & MASK;
fputc(BASE64[OutChar], out);
OutChar = ConvertChar & MASK;
fputc(BASE64[OutChar], out);
fputc('=', out);
}
fputc('=', out);
fputc('=', out);
fputc('=', out);
fputc('=', out);
fclose(in);
fclose(out);
printf("write ok !");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -