Chinaunix首页 | 论坛 | 博客
  • 博客访问: 573725
  • 博文数量: 493
  • 博客积分: 2891
  • 博客等级: 少校
  • 技术积分: 4960
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 17:11
文章分类

全部博文(493)

文章存档

2010年(493)

分类:

2010-04-28 17:35:43

#define PUC_KEY {0x3D, 0x4A, 0x3D, 0x4B, 0x3D, 0x4A, 0x3D, 0x4B, 0x3D, 0x4A, 0x3D, 0x4B, 0x3D, 0x4A, 0x3D, 0x4B}
#define CHAR64(c)  (((c) < 0 || (c) > 127) ? -1 : index_64[(c)])
static signed char index_64[128] = { 
     -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, 
     -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, 
     -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63, 
     52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1, 
     -1, 0, 1, 2,  3, 4, 5, 6,  7, 8, 9,10, 11,12,13,14, 
     15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1, 
     -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40, 
     41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1 
};
int base64_decode(char *psz_decode, const char *psz_encode, int *i_ret_len) 
{  
 int c1, c2, c3, c4;
 
 *i_ret_len = 0;
 
 while (1)
     { 
  if (psz_encode[0]==0)
  {
   *psz_decode = '\0' ;
    break;
  }
         c1 = psz_encode[0]; 
         if (CHAR64(c1) == -1)
         {
             return -1;
         }
 
         c2 = psz_encode[1]; 
         if (CHAR64(c2) == -1)
         {
             return -1;
         }
 
         c3 = psz_encode[2]; 
         if ((c3 != '=') && (CHAR64(c3) == -1))
         {
             return -1;
         }   
        
         c4 = psz_encode[3]; 
         if ((c4 != '=') && (CHAR64(c4) == -1))
         {
             return -1;
         }
 
         psz_encode += 4; 
         *psz_decode++ = (CHAR64(c1) << 2) | (CHAR64(c2) >> 4); 
         *i_ret_len += 1; 
 
         if (c3 != '=')
         { 
             *psz_decode++ = ((CHAR64(c2) << 4) & 0xf0) | (CHAR64(c3) >> 2); 
             *i_ret_len += 1; 
             if (c4 != '=')
             { 
                 *psz_decode++ = ((CHAR64(c3) << 6) & 0xc0) | CHAR64(c4); 
                 *i_ret_len += 1; 
             }
         } 
 } 
   
    return 0;
}
阅读(867) | 评论(0) | 转发(0) |
0

上一篇:交换

下一篇:encr

给主人留下些什么吧!~~