?? crypt.cpp
字號:
// Crypt.cpp: implementation of the CCrypt class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zhaoliang.h"
#include "Crypt.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
// 常量
#define C1 52845
#define C2 22719
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCrypt::CCrypt()
{
}
CCrypt::~CCrypt()
{
}
CString CCrypt::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);
str.SetAt(1, 65+j%26);
Result += str;
}
return Result;
}
CString CCrypt::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<S.GetLength(); i++) // 依次對字符串中各字符進行操作
{
Result.SetAt(i, (BYTE)S.GetAt(i)^(Key>>8)); // 將密鑰移位后與字符異或
Key = ((BYTE)S.GetAt(i)+Key)*C1+C2; // 產生下一個密鑰
}
return Result;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -