#!/usr/bin/python
import sys
import string
alphabet_letters = string.ascii_letters
# ciphered_text:plain_text (c:v)
substitution_dict = {'a':'p' ,'b':'b' ,'c':'m', 'd':'s', 'e':'o', 'f':'*',
'g':'w', 'h':'*', 'i':'k', 'j':'a', 'k':'t', 'l':'h',
'm':'n', 'n':'*', 'o':'r', 'p':'*', 'q':'g', 'r':'y',
's':'u', 't':'f', 'u':'d', 'v':'c', 'w':'i', 'x':'v',
'y':'e', 'z':'l'}
alphabet_substituted = ""
for c in alphabet_letters:
if c in string.ascii_lowercase:
alphabet_substituted += substitution_dict[c]
elif c in string.ascii_uppercase:
if substitution_dict[c.lower()] is not '*':
alphabet_substituted += substitution_dict[c.lower()].upper()
else:
alphabet_substituted += substitution_dict[c.lower()]
with open("crypted.txt", "r") as fh:
encoded_data = fh.read()
if (sys.version_info > (3, 0)):
# made with python 3.5.2
table = str.maketrans(alphabet_letters, alphabet_substituted)
else:
# made with python 2.7.12
table = string.maketrans(alphabet_letters, alphabet_substituted)
decoded_data = encoded_data.translate(table)
print("=== Encoded data ===")
print(encoded_data)
print("=== Decoded data ===")
print(decoded_data)