In this assignment you will create a simple encryption scheme using a binary search tree. To encode a sentence, insert each letter into a binary tree using the ASCII value as a comparative measure.
To encode the sentence meet me, start by inserting the letters "m", followed by "e" and followed by "t" into the binary tree. In the first insertion, the binary tree is empty, so "m" becomes the root node of the tree. The "e" is inserted next. Since "e" is less than "m", it becomes the left child of "m" node. The second "e" is not inserted as there is an "e" in the tree already. The "t" becomes the right child of the "m" node. The next character is the space character and is considered less than any letter and becomes the left most leaf.
To encode, use the following convention: assign the root node of the tree a "*" character. Every other character in the tree, assign a character string based on how many "lefts" and how many "rights" are involved in the tree traversal. For "left" traversals, use a "<", for "right" traversals use a ">". In the above example, "e" will be represented as "<" and "t" will become ">". The space character will become "<<". To complete the code, every character must be separated by a marker called the delimiter. Use "!" (the exclamation mark) as a delimiter for the code.
Using these conventions, the string "meet me" when encrypted becomes "*!<!<!>!<<!*!<".
For this assignment we are only going to encrypt lower case letters "a" through "z" and the space character. When the input string is given for encryption, convert it to lower case. Only encrypt the lower case letters and spaces. Ignore all digits, punctuation marks, and special characters. Basically, you will drop the the digits, punctuation marks and special characters.
For the encryption to work, a key has to be given. This key is used to create the binary search tree. The encryption key for this assignment will be pangrams. A pangram is a sentence where every letter of the alphabet is used at least once. Here are examples of pangrams:
the quick brown fox jumps over the lazy dog pack my box with five dozen liquor jugs the five boxing wizards jump quickly
You will have to modify the Binary Search Tree code given in class. Here is a suggested outline of that:
class Tree (object): # the init() function creates the binary search tree with the # encryption string. If the encryption string contains any # character other than the characters 'a' through 'z' or the # space character drop that character. def __init__ (self, encrypt_str): # the insert() function adds a node containing a character in # the binary search tree. If the character already exists, it # does not add that character. There are no duplicate characters # in the binary search tree. def insert (self, ch): # the search() function will search for a character in the binary # search tree and return a string containing a series of lefts # (<) and rights (>) needed to reach that character. It will # return a blank string if the character does not exist in the tree. # It will return * if the character is the root of the tree. def search (self, ch): # the traverse() function will take string composed of a series of # lefts (<) and rights (>) and return the corresponding # character in the binary search tree. It will return an empty string # if the input parameter does not lead to a valid character in the tree. def traverse (self, st): # the encrypt() function will take a string as input parameter, convert # it to lower case, and return the encrypted string. It will ignore # all digits, punctuation marks, and special characters. def encrypt (self, st): # the decrypt() function will take a string as input parameter, and # return the decrypted string. def decrypt (self, st):You may add other helper functions as needed. There is no need to add a delete function.
Input: You will read your input from a file encrypt.txt. The first line is the encryption key - all the letters will be in lower case. There may be one or more spaces in the encryption key. The second line will be the plain text message to be encoded. The third line will be an encrypted message that you will have to decode. Your file will look like so:
meet me meet me *!<!<!>!<<!*!<In this example, we did not use a pangram as the encryption key in the interest of space. In the actual test cases only pangrams will be used as encryption keys.
Output: The first line of your output will be the encryption of the plain text and the second line of the output will be the plain text of the message that you were asked to decode.
*!<!<!>!<<!*!< meet me
For this assignment you may work with a partner. If you do, both of you must read the paper on Pair Programming. Only one of you will submit the program. Make sure that you have your partner's name and UT EID in the header of your program in HackerRank.
Use the HackerRank system to submit your code. We should receive your work by 11 PM on Monday, 27 Apr 2020. There will be substantial penalties if you do not adhere to the guidelines. HackerRank will not assign late penalties (if any), we will make the adjustments.