• 24 Dec 2008 /  Programming

    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!

    Tags: , , ,