Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- # Create the dictionary for the encryption codes.
- codes = {'A':'!', 'a':'0', 'B':'@', 'b':'9', 'C':'#',
- 'c':'8', 'D':'$', 'd':'7', 'E':'%', 'e':'6',
- 'F':'^', 'f':'5', 'G':'&', 'g':'4', 'H':'*',
- 'h':'3', 'I':';', 'i':'2', 'J':'~', 'j':'1',
- 'K':'x', 'k':'?', 'L':'b', 'l':'Y', 'M':'e',
- 'm':'q', 'N':'a', 'n':'c', 'O':'f', 'o':'D',
- 'P':'j', 'p':'G', 'Q':'B', 'q':'J', 'R':'K',
- 'r':'E', 'S':'A', 's':'d', 'T':'I', 't':'L',
- 'U':'C', 'u':'>', 'V':'<', 'v':'/', 'W':'F',
- 'w':'k', 'X':'r', 'x':'R', 'Y':'t', 'y':'o',
- 'Z':'n', 'z':'s', ' ': ' '}
- # Get the encrypted word file.
- encrypted_file = 'encrypted_words.txt'
- # Decrypt the file and print it out.
- print('Below are the decrypted words:')
- print()
- print(decryption(codes, encrypted_file)
- # the decryption function accepts the codes and the encrypted
- # words, inverts the key-value pair in the codes and decrypts
- # the encrypted words.
- def decryption(codes, encrypted_file):
- # Create an empty string to stored the decryption.
- decrypted_words = ''
- # Create another dictionary with the key-value pair
- # inverted.
- inverted_codes = {val: key for key, val in codes.items()}
- # Open the encrypted file for reading.
- with open(encrypted_file) as file_object:
- decrypted = file_object.read()
- # Perform the decryption.
- for char in decrypted:
- if char in inverted_codes:
- decrypted_words += inverted_codes[char]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement