Skip to content

Instantly share code, notes, and snippets.

@stephenpaulger
Created March 12, 2012 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenpaulger/2020941 to your computer and use it in GitHub Desktop.
Save stephenpaulger/2020941 to your computer and use it in GitHub Desktop.
Why two time pads are a BadThing™
#!/usr/bin/env python
def xor_int_tuple(tup):
return reduce(lambda a,b:a^b, tup)
def xor_tuple(tup):
return ord(tup[0]) ^ ord(tup[1])
def encrypt(m, k, op=xor_tuple):
return map(op, zip(m, k))
k = "abcdefg"
c1 = encrypt("Stephen", k)
c2 = encrypt("Joanna", k)
print c1
print c2
print encrypt(c1, c2, op=xor_int_tuple)
print encrypt("Stephen", "Joanna")
@stephenpaulger
Copy link
Author

[50, 22, 6, 20, 13, 3, 9]
[43, 13, 2, 10, 11, 7]
[25, 27, 4, 30, 6, 4]
[25, 27, 4, 30, 6, 4]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment