Question: Q4.The problem you are tackling in this assignment is the design and implementation of an encryption system. This is not a state-of-the-art encryption system and
Q4.The problem you are tackling in this assignment is the design and implementation of an encryption system. This is not a state-of-the-art encryption system and most likely not useful in real-world scenarios but something you might have used as kids when you wanted to send secret messages to your friend. The encryption works by mapping the letters of the alphabet to other letters. In the simplest case, you might just map each letter to a letter further down in the alphabet, like a to d, b to e, c to f, and so on. Or you might decide to use a more complex mapping that is less easy to guess. You dont have to worry about finding an adequate mapping, because this will be provided by the user of your system. Task 1: Setting up dictionaries (worth 4%) Write a function createDictionaries() that takes a file path as argument and creates encoding and decoding dictionaries from the information provided in the file. Each line of the file contains two letters. The first letter denotes the letter to be encoded. The second letter is the encoding of that letter. The letters are separated by whitespace. For example: a d b e c f The function createDictionaries() reads the lines from the file and creates a dictionary from the lines in which the first letter of each line is a key and the second letter its value. It then assigns this dictionary to the global variable encoding: encoding = { 'a': 'd', 'b': 'e', 'c': 'f', } After that, the function creates a second dictionary with the keys and values swapped and assigns it to the global variable decoding: decoding = { 'd': 'a', 'e': 'b', 'f': 'c', } Once the dictionaries have been set up successfully, createDictionaries() returns the value 0. Task 2: Making createDictionaries() more robust (worth 4%) For Task 1, the assumption is that no errors occur during the setup of the dictionaries. In this task, you make the function more robust by checking for a number of abnormal situations. If such a situation occurs, createDictionaries() does not change any dictionaries and returns a different value from 0, depending on the situation: The file path provided as argument to createDictionaries() is not valid. Check for this situation by using try-except and catching the appropriate error. The value returned by createDictionaries() is 1 in this situation. There is a line in the file that does not contain exactly two letters. Check for this situation by determining the number of letters in each line. Return 2 as value of the function. A key (i.e. the first letter of a line) appears more than once in the file. Check for this situation by making sure that a key is not already in the dictionary before adding a key-value pair. Return the value 3. A value (i.e. the second letter of a line) appears more than once in the file. Check for this situation in a similar way as for the previous one. Return the value 4. Task 3: Encoding and decoding strings (worth 4%) Write two functions encode() and decode() for encoding and decoding strings, respectively. Each function takes a string as argument and then use either the dictionary encoding or decoding to produce a new string, which is returned as value. Use try-except to make sure that the encoding or decoding does not cause an error if the dictionary does not contain all necessary keys for encoding or decoding the argument. If this is the case, return the string #####. Task 4: Create a module (worth 3%) Last but not least turn your code into a module with an appropriate general documentation comment and more specific documentation comments for the functions defined in the modules.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
