Question: this code has been given already to us import random # Given a dictionary d and value v, # find and return the key associated


Question 3 [40 points) In cryptography, a simple substitution cypher is a method of encryption in which each letter of a phrase is replaced by a different letter or sequence of letters. The phrase can then be decrypted by performing the inverse of the substitution. In this question, we will implement a simple substitution cypher in which a character (letter, number, or special symbol) is substituted by a two-digit number between 00 and 99 (inclusive). For example, the letter 'a' could be encrypted to become the number '06', or the special symbol '!' could become the number '57'. We will use a dictionary to store the mapping between each character and its corresponding en- crypted form. That is, the keys of the dictionary will be the regular characters (letters, numbers and special symbols), and the values will be the encrypted forms of the characters (the two-digit! numbers between 00 and 99). Your code should implement the following five functions for this question. Name: create_cypher dictionary Parameters: No parameters Return value: A dictionary where each key is a regular character and each value is a random two-digit number between 00 and 99, inclusive. What it should do: At the top of the code provided to you, the string LETTERS is defined. This string contains all the letters, numbers and special symbols that should be keys in the dictionary. You will have to loop over this string, and generate a two-digit random number between 00 and 99 for each character. The two-digit numbers will be the values in the dictionary; each character (key) will have one two-digit number (value). Note that the numbers 0, 1, 2, ..., 9 should not be ould be the numbers 00, 01, 02, ...,09. Further, note that each character should have a unique random number. That is, if the character 'a' maps to the value '57', no other Rey will have one two-digit numer (varte). Note that the MOOTS U, 1, 2, ..., y should not be values; instead, they should be the numbers 00, 01, 02, ..., 09. Further, note that each character should have a unique random number. That is, if the character 'a' maps to the value '57', no other character should map to the value '57'. (You will need to use some sort of loop to keep generating new random numbers until a unique one is found.) Name: encrypt Parameters: A string s. Return value: The encrypted version of the string s. Each character of the original string s should be replaced by its corresponding two-digit number in the cypher dictionary. Name: decrypt Parameters: A string s. Return value: The decrypted version of the string s. Each two-digit number of the encrypted string s should be replaced by its correponding character in the cypher dictionary. Note that here, we have the encrypted form (value in the dictionary), and are looking to find the regular character (key in the dictionary). To do this, we will need to use the reverse lookup function as seen in class. This function has been provided to You in the included ancruntia nu file The_Gradient_an....... Fundamental In....pdf A M ATH 262 assi....pdf in the dictionary). To do this, we will need to use the reverse lookup function as seen in class. This function has been provided to you in the included encryption.py file. We will write two further functions to increase the strength of our encryption. One function will repeatedly encrypt the string multiple times. The other function will attempt to decrypt the string, without knowing the number of times it was encrypted (thus defeating the point of the stronger encryption) Name: encrypt multiple times Parameters: A string s and integer value n for the number of times to encrypt the string, Return value: The string s encrypted n times. Le., the string will be encrypted a first time, with each character turned into its two-dig representation. Then, the encrypted string will be re- encrypted, with each digit turned into its two-digit representation. (The length of the string will thus double after every encryption.) (Hint: You will have to call your encrypt function multiple times.) Name: decrypt multiple times Parameters: A string s. Return value: The decrypted version of the string s. As we do not know how many times to decrypt the string, we will keep calling decrypt on the string until the string contains a common word in the English language. A list of common words, COMMON WORDS, has been provided for you in the encryption.py file. If, after decrypting once, the string contains any word in this list, then you should immediately return the decrypted string. Otherwise, continue calling decrypt on the string until it does contain one of the common words. (We will assume that the fully decrypted string will always contain at least one common word.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
