Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vernam XOR Stream Cipher with the Mauborgne Constraint
def vernam_decrypt(ciphertext, key):
return bytearray(
[ ciphertext[i] ^ key[i]
for i in xrange(len(ciphertext))
])
#!/usr/bin/env python
from os import urandom
def vernam_genkey(length):
return bytearray(urandom(length))
def vernam_encrypt(plaintext, key):
return bytearray(
[ plaintext[i] ^ key[i]
for i in xrange(len(plaintext))
])
def vernam_decrypt(ciphertext, key):
return bytearray(
[ ciphertext[i] ^ key[i]
for i in xrange(len(ciphertext))
])
plaintext = bytearray('encrypt me')
key = vernam_genkey(len(plaintext))
print 'Before encrypting: ' + plaintext
ciphertext = vernam_encrypt(plaintext, key)
print 'After encrypting: ' + ciphertext
plaintext2 = vernam_decrypt(ciphertext, key)
print 'After decrypting: ' + plaintext2
def vernam_encrypt(plaintext, key):
return bytearray(
[ plaintext[i] ^ key[i]
for i in xrange(len(plaintext))
])
from os import urandom
def vernam_genkey(length):
return bytearray(urandom(length))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.