from random import shuffle
from tkinter.filedialog import askopenfilename
# Read the enciphered message
with open('encipher.txt', 'r') as infile:
cipher_text = infile.read().rstrip().replace('\n', ' ').lower()
# Read the key
with open('key.txt', 'r') as keyfile:
key = list(keyfile.read().rstrip())
# Standard alphabet plus space
alph = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', ' ']
if len(key) < 27:
key.append(' ')
# Decipher the message
plain_text = ''
for c in cipher_text:
if c in key:
idx = key.index(c)
plain_text += alph[idx]
else:
plain_text += c
# Write the deciphered message to file
with open('decipher.txt', 'w') as outfile:
outfile.write(plain_text)
print(plain_text)
Comments
Displaying 0 of 0 comments ( View all | Add Comment )