首页
社区
课程
招聘
未解决 [求助]改写的base64编码部分
发表于: 2019-7-11 11:23 1874

未解决 [求助]改写的base64编码部分

2019-7-11 11:23
1874
参照了linux里面base64的设计思路,编码的时候每行76个字符。
实现的编码,和linux自带工具的base64结果不同。

下面第一部分是linux自带工具生成编码的结尾部分,第二个是自己改写的部分生成的
编码部分结尾

VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuOTJVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVU=

VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuOTJVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVX//w==



贴上代码,不知道问题错在哪里?

void encoding(char *sourcefile,char *destfile)
{
    FILE *file,*dest;
    file=fopen(sourcefile,"rb");
    dest=fopen(destfile,"wb");
    byte f[3];
//    int flag=0;      // 这个是换行标志
    if(file==NULL)
    {
        printf("Cannot open the %s file!",sourcefile);
        exit(1);
    }
    
    int i=0;
    int c;
    int row=0;          // 增加的代码,每行76个字符
    
    while(!feof(file))
    {
        f[i]=fgetc(file);
        i++;
        if(i==3)
        {
            c=(f[0]>>2)&0x3F;
            
             if ( row==76 )
            {
               fputs("\n",dest);
               row = 0;
             }
         //   writechar(c,&flag,dest);
            fputc(code[c],dest);
            row++;

            c=((f[0]<<4)|(f[1]>>4))&0x3F;
            
            if ( row==76 )
            {
               fputs("\n",dest);
               row = 0;
             }
            // writechar(c,&flag,dest);
            
            fputc(code[c],dest);
            row++;

            c=((f[1]<<2)|(f[2]>>6))&0x3F;
            
             if ( row==76 )
            {
               fputs("\n",dest);
               row = 0;
             }
             
            //writechar(c,&flag,dest);
            fputc(code[c],dest);
            row++;

            c=f[2]&0x3F;
            
            if ( row==76 )
            {
               fputs("\n",dest);
               row = 0;
             }
             
            //writechar(c,&flag,dest);
            fputc(code[c],dest);
            row++;
            i=0;
        }
    }

    if(i==1)
    {
        c=(f[0]>>2)&0x3F;
        
        if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
       
        //writechar(c,&flag,dest);
        fputc(code[c],dest);
        row++;
        
        c=(f[0]<<4)&0x3F;
        
        if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
        //writechar(c,&flag,dest);
        fputc(code[c],dest);
        row++;
        
           if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
        fputc('=',dest);
        row++;
           if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }        
        fputc('=',dest);
        row++;
    }

    if(i==2)
    {
        c=(f[0]>>2)&0x3F;
        
        if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
//       writechar(c,&flag,dest);
        fputc(code[c],dest);
        row++;
        
        c=((f[0]<<4)|(f[1]>>4))&0x3F;
        
        if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
        //writechar(c,&flag,dest);
        fputc(code[c],dest);
        row++;
        
        c=(f[1]<<2)&60;
        
        if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
        //writechar(c,&flag,dest);
        fputc(code[c],dest);
        row++;            // 增加的代码
        if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
        if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
        fputc('=',dest);      // 这句没有被执行到
        row++;
           if ( row==76 )
        {
           fputs("\n",dest);
           row = 0;
        }
        fputc('=',dest);     // 这句没有被执行到
        row++;                // 增加的代码
    }
    fclose(dest);
    fclose(file);
}



[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回
//