''' DS2000 Spring 2023 Sample code from class - decryption! Lookup table header ==> a b c d a a b c d b b c d a c c d a b d d a b c Look up key in the first column Find word in the corresponding list Get decrypted letter from the header Given: key bdad word babd Result = abba ''' HEADER = ["a", "b", "c", "d"] LOOKUP = {"a" : ["a", "b", "c", "d"], "b" : ["b", "c", "d", "a"], "c" : ["c", "d", "a", "b"], "d" : ["d", "a", "b", "c"]} def decrypt(key, word, header, lookup): ''' Function: decrypt Parameters: key (string), word (string), header (list of strings), lookup (dictioanry of string: list) Returns: a string Does: uses vigenere cipher to look up each kye's list, find the position of the word in the list and retrieve that position from the header ''' decrypted = "" for i in range(len(key)): # get the current letter in the key, # find the list that goes with it key_letter = key[i] lst = lookup[key_letter] # get the current letter in the word # find its position in the list word_letter = word[i] pos = lst.index(word_letter) # retrieve the letter from header at the same pos decrypted_letter = header[pos] decrypted += decrypted_letter return decrypted def main(): # sanity check version, a one-letter word key = "a" word = "b" expected = "b" actual = decrypt(key, word, HEADER, LOOKUP) print("I decrypted and expected.....", expected, "\nand got.......", actual) # sanity check version, a one-letter word key = "b" word = "d" expected = "c" actual = decrypt(key, word, HEADER, LOOKUP) print("\nI decrypted and expected.....", expected, "\nand got.......", actual) # actual decryption key = "bdad" word = "babd" expected = "abba" actual = decrypt(key, word, HEADER, LOOKUP) print("\nI decrypted and expected.....", expected, "\nand got.......", actual) main()