So, a long time ago (probably 2 years), I created 2 functions using the GameMaker engine that did super simple XOR encryption. XOR encryption is often debatable as being true encryption or not; but I call it encryption anyway. It’s easy to crack and should NOT be used for sensitive data, there are stronger methods out there. Now, onto the simple and short source.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | public String xorEnc(int encKey, String toEnc) { /* Usage: str = xorEnc(integer_key,string_to_encrypt); Created by Matthew Shaffer (matt-shaffer.com) */ int t=0; String s1=""; String tog=""; if(encKey>0) { while(t < toEnc.length()) { int a=toEnc.charAt(t); int c=a ^ encKey; char d=(char)c; tog=tog+d; t++; } } return tog; } public String xorEncStr(String encKey, String toEnc) { /* Usage: str = xorEnc(string_key,string_to_encrypt); Created by Matthew Shaffer (matt-shaffer.com) */ int t=0; int encKeyI=0; while(t < encKey.length()) { encKeyI+=encKey.charAt(t); t+=1; } return xorEnc(encKeyI,toEnc); } |
I’m not going to bother explaing much how these two functions work. Using them is simple and you should read the comments in the functions, and I’m pretty sure all you want to do is rip them anyway. xorEncStr basically converts the string key you provide it into an integer and passes it to xorEnc. Both of the above functions have been tested to work!


January 21st, 2009 at 3:25 pm
Superb. But where is the reverse of this?
January 21st, 2009 at 3:32 pm
I spoke too early. This is what I was looking for. A simple way to encrypt and decrypt without having a burden to use heavy weight encryption techniques. I needed a simple solution and this is it. My users are very gentle people and when they see something encrypted, they will not try to break it. Locks are for fools and not for thieves.
Thanks
January 21st, 2009 at 4:41 pm
Yes, the nature of XOR encryption is that one function works both ways
. This is very simple encryption, but please also note that I have not yet been able to get it working for entire files (Although you could read it in line by line or something if you have a simple file structure already in place).
I’m also with you on the fact that most do not bother when they see something that looks encrypted.
May 25th, 2010 at 2:22 am
Do you have source for Decrypt the same.
Thanks