View code
# Include "stdafx. H"
# Include <iostream>
# Include <ctime>
Using namespace STD;
Void makecode (char * pstr, int * pkey );
Void cutecode (char * pstr, int * pkey );
Int _ tmain (INT argc, _ tchar * argv [])
{
Int key [] = {1, 2, 4, 5}; // encrypted character
Char s [] = "www.xiaozhuanggushi.com ";
Char * P = s;
Cout <"before encryption:" <p <Endl;
Makecode (S, key); // Encryption
Cout <"after encryption:" <p <Endl;
Cutecode (S, key); // decrypt
Cout <"after decryption:" <p <Endl;
Int C;
Cin> C;
Return 0;
}
// Single-character exclusive or operation
Char makecodechar (char C, int key ){
Return C = C ^ key;
}
// Decrypt a single character
Char cutcodechar (char C, int key ){
Return C ^ key;
}
// Encryption
Void makecode (char * pstr, int * pkey ){
Int Len = strlen (pstr); // get the length
For (INT I = 0; I <Len; I ++)
* (Pstr + I) = makecodechar (* (pstr + I), pkey [I % 5]);
}
// Decrypt
Void cutecode (char * pstr, int * pkey ){
Int Len = strlen (pstr );
For (INT I = 0; I <Len; I ++)
* (Pstr + I) = cutcodechar (* (pstr + I), pkey [I % 5]);
}