VC对密码加密和解密函数

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

CString CDlgLogin::Decrypt(CString S, WORD Key)

{

CString Result,str;

int i,j;

Result.Empty(); //清除结果

for(i=0; i < S.GetLength()/2; i++) // 将字符串两个字母一组进行处理

{

j = ((BYTE)S.GetAt(2*i)-65)*26;

j += (BYTE)S.GetAt(2*i+1)-65;

str="1"; // 设置str长度为1

str.SetAt(0, j);

Result+=str; // 追加字符,还原字符串

}

S=Result; // 保存中间结果

for(i=0; i

{

Result.SetAt(i, (BYTE)S.GetAt(i)^(Key>>8)); // 将密钥移位后与字符异或

Key = ((BYTE)S.GetAt(i)+Key)*C1+C2; // 产生下一个密钥}

return Result;

}

CString CDlgLogin::Decrypt(CString S, WORD Key) // 解密函数

{

CString Result,str;

int i,j;

Result.Empty(); // 清楚结果

for(i=0; i < S.GetLength()/2; i++) // 将字符串两个字母一组进行处理

{

j = ((BYTE)S.GetAt(2*i)-65)*26;

j += (BYTE)S.GetAt(2*i+1)-65;

str="1"; // 设置str长度为1

str.SetAt(0, j);

Result+=str; // 追加字符,还原字符串

}

S=Result; // 保存中间结果

for(i=0; i

{

Result.SetAt(i, (BYTE)S.GetAt(i)^(Key>>8)); // 将密钥移位后与字符异或

Key = ((BYTE)S.GetAt(i)+Key)*C1+C2; // 产生下一个密钥

}

return Result;

}

相关文档
最新文档