If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

XOR Encryption Attempt

Okay, I've been following a thread on here where an AO user explained XOR to me (I forget who, sorry). But anyways, I wrote a simple C++ app that takes an input file, and XOR's it against the corresponding bytes of another file, and outputs it to an encrypted file...but my problem is, why doesn't it decrypt correctly...when I encrypted a TXT file with "hello", i got some weird ASCII characters...expected. But when I decrypted it, I got "helloou". I used the key "this is garbage.".

Zeroth remark: It was [SirDice/]Tim_axe...
First remark: Assign the main-function with a return type.
Second remark: Avoid any call to [f]eof. I always have trouble with it.
Here in this case, it spoils the length of the input by 1. Hence, your
decrypted file has a length +2 in the end.
Third remark: Avoid to read in byte by byte. The performance is bad.
Read the whole thing in in one operation. Here is a working code:

You really should do some reading. Solving a little problem by yourself
helps you to keep that stuff in mind - hence, you will make progress.
Copy and pasting prepared code, even when you "look" at it, does not
help to improve your skills. Be independent!

Note, that the number of bytes read can be smaller than the filelength.
This is due to a reinterpretation of 0x10h and 0x13h. You can use the
filelength, determined by the low-level io routines, as an input of the
istream of course.

Cheers.

If the only tool you have is a hammer, you tend to see every problem as a nail.
(Abraham Maslow, Psychologist, 1908-70)