C/C++ 字串加密 可列印文本加密,字串列印文本
今天做了一個文本密碼編譯演算法, 由於是這個演算法是基於演算法保密的,沒有秘鑰,所有只能應付安全要求不高的需求,
如下
原文1
201411210H0g//60609.820
密文1
{*<P^o!1ARcw%8MXoz4;=fm i
原文2
201411210ab1234/32d fds
密文2
s"4HVgy)9J[o}0EPgs#35^Fxa
每次加密一行資料!!
希望大家喜歡
//strOut必須為可列印字元0x20 -- 0x7F//strOut必須以'\0'結尾,//加密效果較好 By Sols// 加密結果為可列印字元0x20 -- 0x7Fvoid EnCodeStr(char *strOut){int randOffset = rand()%96;int ResChar ;int i=0;for (;strOut[i] != '\0';i++){ResChar = randOffset + strOut[i] + i*17;//17可以為其他合適的數字while ( ResChar > 127){ResChar -= 96;}strOut[i] = (char)ResChar;}strOut[i++] =(char)( randOffset + 32 );strOut[i] = '\0';}//strOut必須為可列印字元 0x20 -- 0x7F//strOut必須以'\0'結尾,void DeCodeStr(char *strCode){int KeyIndex = 0;if (strCode[0] == '\0') return;while( strCode[KeyIndex] != '\0'){KeyIndex++;}int Key = (int)(strCode[KeyIndex-1]) - 32;int ResChar ;int i=0;for ( ;strCode[i] != '\0';i++){ResChar = strCode[i] - Key - i*17;while ( ResChar < 32){ResChar += 96;}strCode[i] = (char)ResChar;}strCode[i-1] = '\0';}