1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
import sys import string
alphabet_letters = string.ascii_letters
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)): table = str.maketrans(alphabet_letters, alphabet_substituted) else: 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)
|