search

Home  >  Q&A  >  body text

c++ 加密程序用php怎么写?

#define C1 34783
#define C2 55419
CString Encrypt(CString S, WORD Key) // 加密函数
{
    CString Result,str;
    int i,j;
    Result=S; // 初始化结果字符串
    for(i=0; i<S.GetLength(); i++) // 依次对字符串中各字符进行操作
    {
        Result.SetAt(i, S.GetAt(i)^(Key>>8)); // 将密钥移位后与字符异或
        Key = ((BYTE)Result.GetAt(i)+Key)*C1+C2; // 产生下一个密钥
    }
    S=Result; // 保存结果
    Result.Empty(); // 清除结果
    for(i=0; i<S.GetLength(); i++) // 对加密结果进行转换
    {
        j=(BYTE)S.GetAt(i); // 提取字符
        // 将字符转换为两个字母保存
        str="12"; // 设置str长度为2
        str.SetAt(0, 65+j/26);//这里将65改大点的数例如256,密文就会变乱码,效果更好,相应的,解密处要改为相同的数
        str.SetAt(1, 65+j%26);
        Result += str;
    }
    return Result;
}
大家讲道理大家讲道理2901 days ago264

reply all(0)I'll reply

No reply
  • Cancelreply