Skip to content

Instantly share code, notes, and snippets.

@exallium
Created June 20, 2011 02:35
Show Gist options
  • Save exallium/1035036 to your computer and use it in GitHub Desktop.
Save exallium/1035036 to your computer and use it in GitHub Desktop.
XOR Cipher in Python
INFILE="input.txt"
OUTFILE="output.txt"
key = "asdf"
fin = open(INFILE, "rb")
x = fin.read()
l = len(x)
key = key * (l/len(key))
o = ""
index = 0
for item in x:
o += chr(ord(item) ^ ord(key[index]))
index = (index + 1)%len(key)
fin.close()
fout = open(OUTFILE, "w")
fout.write(o)
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment