XOR Encryption

This is a discussion on XOR Encryption within the C++ Programming forums, part of the General Programming Boards category; [QUOTE=matsp;663024]
Also, for future use, you may want to allow more than one encrypted text to exist, so maybe you ...

[QUOTE=matsp;663024]
Also, for future use, you may want to allow more than one encrypted text to exist, so maybe you should just merge the two source-codes to one application, and just decrypt/encrypt all in one thing - that's the beuty of a XOR encryption - it's exactly the same thing to encrypt and decrypt - the only difference is what you've got as an input - clear text or encrypted text.
/QUOTE]

The reason I did that is because for some reason, if the file is truncated, it will only write one letter to it, so I have to append to it. I was forgetting to clear it when I was done, so I ended up with more then one text file encrypted in it.

And with this, there's no need to append to the existing file, just let the normal functionality of "emptying the file" take place. That way, the removal of the file can be removed, and it's a simple program for it. If possible, keep things simple - it's not always possible, but when it is, that's the best way.

Originally Posted by mikeman118 View Post
matsp, (I already said this), for some reason, if I don't append to the file, it will only write the one character to it- that's why I have it append it.

That's because, as someone ALREADY pointed out, you re-open the file every time through the loop.

Oh, right. Hey if this helps anyone if you use "ABCDEFGHIJKLM" as your key, or even just "ABC", it will work just fine. I guess I could just use that as a key, but it's not exactly practical. Hope that helps.

Also, the suggestions about changing how it handled the key seemed to help a little, but it still picked a random letter to do something to (i.e. color it changed to dcolor, for every instance of the letter c).

So, take a simple text file (say one that contains the alphabet in lower and upper case repeated a few times to make your key move to different places), then check out what particular letter is causing the problem. Put a if-statement in your XOR function and check the input value and output value (print them as hex or decimal by casting to an int).

There are a few other letters that do such things, maybe I should just use a key that doesn't use those letters...

Edit: The letters that do not work as the beginning of the key (i.e. they make a ~ appear after certain characters) are:
k
l
m
n
o
p
r
s
Anyone have an idea why only those characters don't work? Thanks.

Edit: I guess that was with only the first letter, if you use a longer key, with some of those characters combined (e.g. eggs, which starts with "e" which should be fine, but it ends in "s"). So that's what's wrong now, I think I'm giving up on it, unless someone else has an idea.