The cypher works by finding the Exclusive OR of each character with a key string. Here it is in Python.
# Vernam cypher demo
# T Street 2015-10-16
def makeVernamCypher( text, key ):
""" Returns the Vernam Cypher for given string and key """
answer = "" # the Cypher text
p = 0 # pointer for the key
for char in text:
answer += chr(ord(char) ^ ord(key[p]))
p += 1
p = 0
MY_KEY = "cvwopslweinedvq9fnasdlkfn2"
PlainText = input("Enter text to encrypt: ")
Cypher = makeVernamCypher(PlainText, MY_KEY)
print("Cypher text: "+Cypher)
decrypt = makeVernamCypher(Cypher, MY_KEY)
|Demo shows the text has been encrypted and then decrypted again.|
Join us again soon for more nerdy stuff.
#Cyper #Vernam #Encryption