|Get Selected Weeks Solution with ONLY||NOT||Add Selected Tutorials To Cart|
A single zip file including the following.
If you document any issues, it will be easier to isolate any problems, provide detailed help, and could potentially improve your grade.
In this Lab, you will create a simple encryption scheme, also called a cipher, using the binary tree ADT. In the process of implementing binary tree operations, you will also be exposed to a common use for binary trees: encryption and data compression.
Part 1: Understanding the Problem—Encrypting a Sentence
Imagine that you are writing a secret code to your best friend that you want only the two of you to be able to understand. As luck would have it, your best friend has also taken GSP295 and has a good understanding of binary trees. You devise a scheme to encode and decode a message based on the creation of a binary tree of its letters.
To encode a sentence, insert each successive letter into a binary tree using the alphabet as a comparative measure; ‘a’ is the smallest character and ‘z’ is the largest.
Take a simple example. To encode the sentence “meet me,” start by inserting the letters ‘m’ followed by ‘e’ followed by ‘t’ into a binary tree. In the first insertion, the binary tree is empty, so ‘m’ becomes the root node of the tree. Second, ‘e’ is inserted. Because ‘e’ is less than ‘m,’ it is placed on the left node of the ‘m’ node and becomes a leaf node. Third, a second ‘e’ is discovered. Because ‘e’ has already been inserted, the second ‘e’ does not result in any change. Lastly, ‘t’ is inserted by first comparing to ‘m’ and then placing it in the right node of the ‘m’ root node since it is greater.
After ‘meet’ the simple binary tree looks like this:
Continue inserting all other letters of the sentence in this fashion. A ‘space’ character (and other punctuation) is considered less than the ‘a’ character. The ‘space’ character is indicated by a simple empty box. When all characters are inserted, the binary tree will look like this:
To encode the message, use a standard convention involving traversing the tree. By convention, simply 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 ‘!’ (an explanation point) as a delimiter for the code.
Using these conventions, “meet me” becomes “*!<!<!>!<<!*!<.”
Extend this example further by drawing the binary tree out on paper for “meet me at the window.” What is the full encoding for this statement?
For encryption of simple English messages, cases and punctuation do not matter. You can assume that the user will be typing letters and spaces and don’t need to worry about punctuation and special characters. The ‘space’ character will evaluate to < ‘a’. This is perfectly normal. Simply make the assumption that your alphabet has 27 characters starting with ‘space’ and ending with ‘z.’
In order to treat all letters equally, assume that capital letters and lowercase letters are the same. To do this, you can convert a user inputted string into lowercase by using the following code segment example
You can also use this code segment as a basis for understanding how to process characters individually from a string, which involves the same basic loop.
Part 2: Creating a Binary Encryption Tree ADT
Step 1: Create the ADT
A binary search tree ADT will be needed in order to complete the Lab. Using the ADT described in the textbook, implement a binary tree structure that holds characters (the key value). For the purposes of this Lab, you will not need to implement the entire ADT. You will need the following operations.
For all binary tree ADT operations, ensure that the binary search tree property is maintained. The key value of any node is greater than the key value of its left child and any of its children and less than the key value of its right child and any of its children.
Further properties are not required. PutItem and DeleteItem operations do not need to ensure the binary tree is balanced. Please also note that you cannot use already existing binary tree include files or APIs. You must implement the ADT using basic data structures as outlined in your textbook in the Binary Search Trees chapter.
Important: Be careful with ‘edge’ or ‘border’ cases. For example, what happens when you delete an item that isn’t in the tree? What happens if you get an item that isn’t in your tree? Your program should not break in these conditions!
Step 2: Modify the GetItem Operation
Now that you’ve created the binary tree ADT you need to make one critical adjustment. Change your ‘GetItem’ operation to return a string of characters consistent with the tree traversal character creation of ‘left’ and ‘right’ from Part 1. Every time GetItem traverses the tree to the right, the “>” character should be appended to the string. Every time that GetItem traverses the tree to the left, the “<” character should be appended to the string. In the end, a call to GetItem should return the complete code for the character being searched for. This can be done by changing the return type or by passing a parameter by reference. Either is sufficient.
Remember that you will need to create a special case for the root node which should return “*”.
Step 3: Add a Traverse Operation
Add a custom Traverse operation to your ADT. This operation should take a string code as a parameter and return the letter stored at the corresponding location in the binary tree.
For example, passing the Traverse operation a string of “<<<” will cause it to traverse the binary tree from the root, down the left node, down the left node of that node, and then down the left node of the resulting node. The traverse operation will then return the letter stored at that node.
Remember that you will need to create a special case for the “*” string which is the root node.
Part 3: Implementing a Test Driver
Now you are ready to create a test driver to test your new encryption and decryption program.
In order to test your system fully, please implement the following test driver commands.
The ‘Create Encryption Tree’ command forms the encryption tree from a string of characters known as the ‘key.’ Both the sender and receiver have to know the encryption key in order to both encode and decode a message. This menu command should do the following.
“Encryption Tree created successfully with 14 nodes”
You must use the CountNotes ADT operation in this command.
Encrypt message performs the actual message encryption by making calls to GetItem. This menu command should do the following.
“Encoded String: *!<!<!>!<<!*!<”
If you are not familiar with string concatenation in C++, you can return the concatenation of two strings by simply ‘adding them’ together. For example
One way to compress a message is to remove characters that aren’t required for its understanding. Vowels are wonderful inventions, but most of the time a message can be understood without them. Create a menu command to remove a character from the encryption key:
“Encryption Tree modified successfully, total nodes: 12”
You must use the CountNotes ADT operation in this command.
Using the binary tree and a code entered from the user, decrypt a message and output it to the user.
“Decryption complete: meet me”
You will have to pre-process the string in order to break it into string codes. Remember that each code is separated by the character “!.”
Remember to remove the “!” or ignore it from your Traverse ADT operation.
Part 4: Testing
In order for your encryption to be useful, the encrypted must be sent to someone with the same encryption key.
Test your program by creating test cases for encryption keys and messages to encode and decode. An excellent test case to use for your encryption key is “the quick brown fox jumps over the lazy dog”. This sentence contains all the letters of the alphabet, therefore, you can test encode and decode any English sentence with it. For the purposes of exchanging encrypted messages this week, use this sentence as the encryption key.
It would be an excellent idea to test your program by communicating with your classmates via secret code on the discussion boards. Post a message to the discussion boards. Try to decrypt a code that someone else posts. Does the message make sense?
In order to communicate with your classmates, use the encryption key: “the quick brown fox jumps over the lazy dog.”
Part 5: (Optional, Not Graded) Compression Further Study
The simple cipher is a poor example of compression because each letter converts into several characters. However, consider if instead of encoding letters, the encoding was done on words. In common conversation, only a few thousand words are commonly used in the English language. If instead of using “<” and “>,” 0 and 1 are used, and the corresponding code is converted to bit strings and a 5,000 word vocabulary can be represented in 13 bits. This is a huge savings over the average string length of a word which even at five characters is at least 10 bytes of storage.
There are additional problems that arise with compression and placing encrypted/compressed codes adjacent to one another in storage. A common compression scheme that is easy to implement by using basic knowledge about binary trees is called Huffman Coding. C++ code is freely available in many places to implement Huffman Coding compression.
Part 6: Lab Questions
Consider and answer the following questions in your Lab write-up.
General iLab Comments
All coding assignments for this class will be using Microsoft Visual Studio. This is available through the Software Store, which can be found in Course Home. Contact the help desk if you encounter any issues or contact your professor.
*Please note as a reminder that you may not copy code from any web reference to complete this assignment, even if you correctly give credit. You may of course use web references to help you understand, but you must code the assignment yourself. You may use code directly from your textbook where applicable, but do make sure you give credit in your comments if you are doing so.
Here is solution for GSP295 - Week 5
It is 100% correct.
Solution contain Visual Studio C++ project and document answer all questions.
If you have more questions, please contact me via email email@example.com
I will help you any time
Thank you very much