const char gamestr[128] =
{0x4E, 0x3E, 0x54, 0x53, 0x56, 0x55, 0x4A, 0x6C, 0x77, 0x64,
0x63, 0x42, 0x4D, 0x46, 0x6A, 0x6E, 0x41, 0x4B, 0x62, 0x3F,
0x71, 0x78, 0x76, 0x79, 0x65, 0x47, 0x7A, 0x66, 0x4C, 0x50,
0x3D, 0x5F, 0x45, 0x52, 0x40, 0x5A, 0x5C, 0x61, 0x6D, 0x5D,
0x43, 0x68, 0x67, 0x6F, 0x57, 0x44, 0x3B, 0x51, 0x75, 0x58,
0x5B, 0x3C, 0x74, 0x6B, 0x70, 0x72, 0x5E, 0x60, 0x69, 0x49,
0x48, 0x4F, 0x59, 0x73, 0x2E, 0x33, 0x1E, 0x01, 0x13, 0x22,
0x10, 0x0B, 0x28, 0x2D, 0x20, 0x0D, 0x19, 0x3C, 0x3B, 0x06,
0x11, 0x1C, 0x0C, 0x00, 0x3D, 0x1D, 0x2F, 0x21, 0x03, 0x02,
0x05, 0x04, 0x2C, 0x31, 0x3E, 0x23, 0x32, 0x24, 0x27, 0x38,
0x1F, 0x39, 0x25, 0x12, 0x0A, 0x09, 0x18, 0x1B, 0x2A, 0x29,
0x3A, 0x0E, 0x35, 0x07, 0x26, 0x0F, 0x2B, 0x36, 0x14, 0x37,
0x3F, 0x34, 0x30, 0x16, 0x08, 0x15, 0x17, 0x1A};
/*加密部分函数
in 输入字符串指针
out 输出字符串指针
len 输入字符串长度
返回 意义
>=0 加密后在out里面的字符串长度
*/
int Encode(char * in, char * out, int len)
{
char a1, d1 ;
int i,count,di,si;
int encode_len = len / 3 * 4; //返回加密后数据长度
int rLen;
rLen=strlen(in);
if(len < 1)
return 0;
for(di = 0, si = 0, count = len / 3, i = 0; i < count; i++)
{
//第一次转换
//每3个字节作为一组(一次循环),输出4个字节(因为第一个被处理了2次)
//第一个字节移位运算
a1 = (in[di] 0xFF) >> 2;
out[si] = a1;
//第一个字节第二次移位运算
a1 = (in[di] 3) << 4;
d1 = (in[di + 1] 0xFF) >> 4;
a1 = a1 | d1;
out[si + 1] = a1;
//第二个字节移位运算
a1 = (in[di + 1] 0x0F) << 2;
d1 = (in[di + 2] 0xFF) >> 6;
a1 = a1 | d1;
out[si + 2] = a1;
//第三个字节移位运算
a1 = in[di + 2] 0x3F;
out[si + 3] = a1;
//第二次转换
//把第一次加密后的数据用索引表中的数据替换一遍
//第一个字节替换
d1 = gamestr[out[si]];
out[si] = d1;
//第二个字节替换
d1 = gamestr[out[si + 1]];
out[si + 1] = d1;
//第三个字节替换
d1 = gamestr[out[si + 2]];
out[si + 2] = d1;
//第四个字节替换
d1 = gamestr[out[si + 3]];
out[si + 3] = d1;
di += 3;
si += 4;
}
// const char* p=gamestr[rLen];
memset(out-1,gamestr[rLen],1);
return encode_len;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!