📄 base64dec.cpp
字号:
#define N (1<<16)
#define TYPE (unsigned short)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int pp(unsigned char *subs,unsigned char *s,int qd);
unsigned char tb[]="base64",tb1[]="BASE64";
main(int argc,char *argv[])
{
int c=0,len=0,i,qd,js,FLAG=0,flag,filejs=1,sum,start,id_0,id_1;
unsigned long mw=0;
unsigned char str[N],word[256];
char fname[]="000000000000";
FILE *fp,*fpw,*fp1;
if(argc<2) {
printf("Usage:%s infile temp_file\n",argv[0]);
exit(-1);
}
if( (fp= fopen(argv[1],"rb"))==NULL ){
printf("cant open file\n");
exit(-1);
}
if ((fp1=fopen("base.b64","ab"))==NULL){
printf(" cant open the windowfile ! \n");
exit (-1);
}
for(i=0;i < 256 ;i++) word[i]=0x15; /* 00010101 */
for(i='A';i <= 'Z';i++) word[i]=(char)(c++)+'0';
for(i='a';i <= 'z';i++) word[i]=(char)(c++)+'0';
for(i='0';i <= '9';i++) word[i]=(char)(c++)+'0';
word['+']=(char)(c++)+'0';
word['/']=(char)(c++)+'0';
for(flag=0,sum=0,qd=0,js=0;;){
if(sum-qd<N/2){
if( (c=getc(fp))==EOF ) break;
str[TYPE(sum++)]=(unsigned char)c;
continue;
}
if((pp(tb,str,qd)==0)||(pp(tb1,str,qd)==0)){
strcpy(fname,"base64.64");
fname[9]=(char)filejs+'0';
fname[10]='\0';
printf("Create file : %s \n",fname);
if ((fpw=fopen(fname,"wb"))==NULL) {
printf("cant open the %s !!\n",fname);
exit(-1);
}
filejs++;
FLAG=1;id_0=qd;
}
if (str[TYPE(qd)]==0x0d&&str[TYPE(qd+1)]==0x0a&&
str[TYPE(qd+2)]==0x0d&&str[TYPE(qd+3)]==0x0a){
start=1;mw=0;len=0;id_1=qd; //id_1=qd+4;
}
if (FLAG==1&&start==1&&(id_1>id_0)){
if (str[TYPE(qd)]!=0x0d&&str[TYPE(qd)]!=0x0a){
mw <<=6; mw |=word[ str[TYPE(qd)] ]; len +=6;
while(len >= 8){
fprintf(fpw,"%c",(mw >> (len-8)) & 0xff);
len -=8;
}
}
else{
if (str[TYPE(qd)]==0x0d&&str[TYPE(qd+1)]==0x0a&&
str[TYPE(qd+2)]==0x0d&&str[TYPE(qd+3)]==0x0a)
js++;
if (js>=2) {js=0;FLAG=0;start=0;id_0=0;id_1=0;fclose(fpw);}
}
}
else
fprintf(fp1,"%c",str[TYPE(qd)]);
qd++;
}
fclose(fp);
fclose(fpw);
return 0;
}
pp(unsigned char *subs,unsigned char *s,int qd)
{
int i;
for(i=0;subs[i];i++,qd++)if(subs[i] != s[TYPE(qd)])return 1;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -