I'm dealing with two strings, one being the string that I want to encrypt using XOR encryption and one being my "key" that I XOR the original string against.
for (a simplified) example:
HOWEVER, the problem is that if by chance szOriginal[i] == szKey[i], the XOR operation will result in 0! This will replace what was a valid character in the string with a null character.Code:while ( szOriginal[i] != '\0' && szKey[i] != '\0' ) { szOriginal[i] = szOriginal[i] ^ szKey[i]; i++; }
Then, when I go to print the encrypted string (or do other things with it), the printing ends prematurely because the new null character terminates it.
How do most programmers deal with this?