Skip to content

Instantly share code, notes, and snippets.

@ihaveamac
Last active June 15, 2016 10:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihaveamac/52d133097afa9e36a4c2812b0663fe84 to your computer and use it in GitHub Desktop.
Save ihaveamac/52d133097afa9e36a4c2812b0663fe84 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import sys
if len(sys.argv) != 3:
print("xor.py <file> <xorpad>")
sys.exit()
encfile = open(sys.argv[1], "rb")
xorpad = open(sys.argv[2], "rb")
outfile = open("%s.out" % sys.argv[1], "wb")
encfile_c = encfile.read()
xorpad_c = xorpad.read(len(encfile_c))
xored = ""
for byte_f, byte_x in zip(encfile_c, xorpad_c):
xored += chr(ord(byte_f) ^ ord(byte_x))
outfile.write(xored)
encfile.close()
xorpad.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment