I'm building my xor encryptor, help with nul character
Well, i noticed someone was building a xor encryptor but wasn't too successful, i decided to take up the challenge.
The program itself is built and it works, however it has one big problem. Whenever the current key character is the same as the current 'clean' character, I get a \0 (pretty "doh" if you ask me, since that's the purpose of XOR). The big problem is that a nul character is also the char terminator.
In my whole program, I'm using a single char variable, the input buffer while reading the file.
Code:
char ch;
while( fin.get( ch ) ) {
filedata.append( &ch );
fsize++;
}
However, it doesn't want to write anything in filedata when it hits a 0.
My input file holds the letters from a to z. my key is "abcde" (repeated over).
So, my first file (clean) is 26 bytes. The encrypted one is 26 bytes. So the data from the string, holding nul characters is written down.
The problem is that my decrypted file (which i get by running the program again through the last generated file) is 21 bytes, and it starts from f. My logical explanation is that the input buffer skips the null characters, believing that it holds a zero-length string.
What can I do?