Project 4: encryption and decryption
Here's my code to encrypt and decrypt a single character. You must also
provide the checksum value each time you call either of these functions.
char encryptChar( int iChecksum0, char c0 )
{
int iChar = (int)c0;
int iEncodedChar = (iChar - 32 + iChecksum0) % 95 + 32;
char cEncodedChar = (char)iEncodedChar;
return cEncodedChar;
}
char decryptChar( int iChecksum0, char c0 )
{
int iChar = (int)c0;
int iDecodedChar = (iChar - 32 - iChecksum0) % 95 + 32 + 95;
if( iDecodedChar > 126 )
iDecodedChar -= 95;
char cDecodedChar = (char)iDecodedChar;
return cDecodedChar;
}