Question 1.
I understand how a 'key' or single ASCII character like the letter 'k' is used to encrypt text. For example, the binary code for:
A: 01000001
k: 01101011
Thus, the encrypted character for A, with the key 'k' would be '*' given its binary code: 00101010.
How does the XOR encryption work when you have more than one character as a key, for example key = "hi"?
Question 2:
I'm using the code below to read (line by line) a text file "test.txt" which encrypts each line before storing it into a vector. This vector is then saved as the text file "newtest.txt". The program then decrypts the encrypted file using the same method / key and save it as "decrpytednewtest.txt".
It seems that the key of 'k' converts the letter 'a' in the original text as a new line in the encrypted file but the decrypted file doesn't correct this...
How do I avoid this occuring in my decrpytednewtest.txt no matter what key I use?
I'll have a look and go at what Duoas posted. My programming understandings is limited but improving ever so slightly.... So I'm up for a new challenge.
I've only ever written data to text files.
The data I am writing to text files will store some of the user's personal data but not too personal... A simple XOR encryption should be enough anyhow.
Is there an advantage to writing / opening in binary mode? Or does it depend on what you're writing and / or the amount of data that is being written??
I would be very appreciative if anyone is willing to give me a brief explanation on my first question above too ;)
Cheers,
Edit: By the way, using ios::binary with my ifstream and ofstream seems to have done the trick.... Thanks!