📄 如何对一个已有字符串加密.txt
字号:
如何对一个已有字符串加密
CString ChangWhiteBlackKey(CString strText,bool bWhite)
{
int i ;
char tCh1,tCh2;
CString strReturn ;
strReturn.Empty();
if(bWhite)//明码=>暗码
{
for(i = 0 ; i < strText.GetLength(); i++)
{
unsigned short int t = strText.GetAt(i) + 11;
if(t > 255)
{
tCh1 = 'A' + rand()%26;
tCh2 = t - 256 +100/* +100避免出现0(结束符) */ ;
}
else
{
tCh1 = '0' + rand()%10;
tCh2 = t ;
}
strReturn = (strReturn + tCh1) + tCh2 ;
}
}
else
{
for(i = 0 ; i < strText.GetLength() ; i+=2)
{
tCh1 = strText[i];
tCh2 = strText[i+1];
unsigned short int t;
if(tCh1 > 'A')
t = 256 + (tCh2 - 100) - 11 ;
else
t = tCh2 - 11 ;
strReturn += t ;
}
}
return strReturn ;
}
简单加密,呵呵,提供一个最简单的
代码仅供参考!
char strKey[] = {0x03,0x25, 0x45, 0x5F, 0xFA};//你的密钥,长度随你定了
CString szData("你的要加密的数据");
char *pData = szData.GetBuffer(0);
char *p = new char[szData.GetLength()];
int nKeyLen = sizeof(strKey);
for(int i=0; i<szData.GetLength(); i++)
{
*pData = *pData ^ strKey[i%nKeyLen];//每字节与对应的密钥字节进行异或运算
pData++;
}
试试吧,提供点思路
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -