• 24 Dec 2008 /  Programming 4 Comments

    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!

    Posted by Matt @ 12:52 am

    Tags: , , ,

4 Responses

WP_Blue_Mist
  • Vikram Says:

    Superb. But where is the reverse of this?

  • Vikram Says:

    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

  • Matt Says:

    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.

  • Pranit Says:

    Do you have source for Decrypt the same.
    Thanks

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.