xor encoder v1.0

This is a simple xor encoder for encoding files.

#!/usr/bin/python

#A simple xor encoder
#Xor the input file with 0-255
#Written by s1n4

import sys

def usage() :
    print 'Usage: %s [Key] [File]' % sys.argv[0]
    print '[Key] 0x00-0xff same as 0-255'
    exit()

def xor(key, fn) :
    try :
        Input = open(fn, 'rb').read()

    except IOError :
        usage()

    res = ''

    for i in Input :
        try :
            res += chr(ord(i) ^ eval(key))

        except :
            usage()

    try :
        Output = open(fn, 'wb')
        Output.write(res)

    finally :
        Output.close()
        print fn, 'xor', key

def main() :
    if len(sys.argv) == 3 :
        xor(sys.argv[1], sys.argv[2])

    else :
        usage()

main()

For example :
xor.py 0x4a test.txt

For access to the original file you must xor again with latest key.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s