xor encoder v2.0

Another version of xor encoder

#!/usr/bin/python

##################################
 #####                      #####
 #####      Xor encoder     #####
 #####   For encoding file  #####
 #####                      #####
 #####    Writen by s1n4    #####
 #####    June 16 , 2011    #####
 #####       3:55 AM        #####
 #####                      #####
##################################

import sys

def usage() :
    print 'Usage: %s [Key] [File]' % sys.argv[0]
    exit()

def xor(key, fn) :
    try :
        Input = open(fn, 'rb').read()
        #Open and read input file

    except IOError :
        usage()

    res = ''
    c = 0

    for i in Input :
        res += chr(ord(i) ^ ord(key[c]))
        #i = byte by byte of Input; key[c] = byte by byte of key; res += i xor key[c]
        if c == len(key) - 1 :
            c = 0
            continue

        c += 1

    try :
        Output = open(fn, 'wb')
        Output.write(res)
        #Replace xored to input file

    finally :
        Output.close()
        print key, 'xor', fn
        #End of the work

def main() :
    if len(sys.argv) == 3 :
        xor(sys.argv[1], sys.argv[2])
        #sys.argv[1] = input key and sys.argv[2] = input file

    else :
        usage()

main()

For example :
xor.py s1n4 test.zip
For access to the original file you must xor again with latest key.

Advertisements

2 thoughts on “xor encoder v2.0

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