Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python (Cryptography) Task 4: Simple Substitution Cipher (4 pts) Implement the simple_Substitution class that provides encryption and decryption operations for the simple substitution cipher. The
Python (Cryptography)
Task 4: Simple Substitution Cipher (4 pts) Implement the simple_Substitution class that provides encryption and decryption operations for the simple substitution cipher. The key is a tuple consisting of (base, sub). The base is a string representing a stream of unique ascii characters, composing of at least 2 characters. The cipher operates in two modes: simple or keyword. Using the simple mode, the sub is a random arrangement of the base, such that all characters in the base also appear in the sub. Using the keyword mode, the sub is structured such that all unique characters in the keyword appear first, then the remaining base characters appear in their respective order. The keyword should contain at least two unique characters. You can think of the simple mode as a special case of the keyword mode, where the keyword is a long word containing all characters in the base. The constructor receives a mode from the user. If the user does not provide the mode, or if it provides anything other than simple or keyword, then it will be set to 's imple'. The mode is initialized once and is not expected to change any time later. The valid_key (key, mode) static method checks if the given key is valid in the context of the given mode. For instance, sub can have a shorter length than the base in the keyword mode, but not the simple mode. The set_key (key) sets the private class property _key to the given key if it is valid. If the provided argument is invalid, key is set to the default key, which is defined as a class-level property. The get_key () method returns a copy of the key. The get_table () method returns a list in the form [base, sub]. For the simple mode, it is straight-forward. However, for the keyword, it should construct the sub before making the return. The encrypt (plalntext) and decrypt (ciphertext) functions use the substitution table to convert from plaintext to ciphertext and vice versa. Only characters defined in the base should be substituted. The case of the letters should be preserved whenever possible. The class overrides the __str built-in method to provide string representation of the class. It should return a string in the following format: Simple Substitution Cipher: mode = mode base string sub string There is no cryptanalysis method for this class. Make sure to get identical results to those showing in exam2_output. txt when you run test_task4 () function. My best wishes Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started