C/C ++ string encryption: printable text encryption; string printing text
Today, we developed a text encryption algorithm. Because it is based on the algorithm's confidentiality and has no key, it can only meet the security requirements,
As follows:
Article 1
201411210H0g // 60609.820
Ciphertext 1
{* <P ^ o! 1 ARcw % 8MXoz4; = fm I
Article 2
201411210ab1234/32d fds
Ciphertext 2
S "4 HVgy) 9J [o} 0 EPgs #35 ^ Fxa
Encrypt a row of data each time !!
Hope you like it
// StrOut must be printable characters 0x20 -- 0x7F // strOut must end with '\ 0, // encryption is better By Sols // The encryption result is printable characters 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 can be a suitable number while (ResChar> 127) {ResChar-= 96;} strOut [I] = (char) ResChar;} strOut [I ++] = (char) (randOffset + 32 ); strOut [I] = '\ 0';} // The strOut must be printable characters 0x20 -- 0x7F // The strOut must end with' \ 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; (; strCode [I]! = '\ 0'; I ++) {ResChar = strCode [I]-Key-I * 17; while (ResChar <32) {ResChar + = 96 ;} strCode [I] = (char) ResChar;} strCode [I-1] = '\ 0 ';}