Discount Get GSP 295 ALL WEEKS Solution ONLY $104.95 $139.93
GSP 295 Week 1 - A Simple ADT [$19.99]
GSP 295 Week 2 - Sorted List Lab [$19.99]
GSP 295 Week 3 - Palindromemordnilap [$19.99]
GSP 295 Week 4 - Horacious Glump [$19.99]
GSP 295 Week 5 - Simple Cipher [$19.99]
GSP 295 Week 6 - Graph ADT [$19.99]
GSP 295 Week 7 - Dijkstra [$19.99]
Get Selected Weeks Solution with ONLY NOT Add Selected Tutorials To Cart
GSP 295 GSP295 GSP/295 - Week 5 - Lab 5 - iLab 5 - Simple Cipher - 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.
    GSP 295 GSP295 GSP/295 - Week 5 - Lab 5 - iLab 5 - Simple Cipher - 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.

GSP 295 GSP295 GSP/295 - Week 5 - Lab 5 - iLab 5 - Simple Cipher - 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.

$19.99

Deliverables

A single zip file including the following.

  • Your Visual Studio Project directory and associated files, including source files for the Lab.
  • The results of your testing. What tests did you run? Did everything work okay? Are there outstanding issues in your program? A short half-page summary of your results is about the right length.
  • Your answers to the Part 6 Lab Questions.

If you document any issues, it will be easier to isolate any problems, provide detailed help, and could potentially improve your grade.

Summary

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.

  • MakeEmpty
  • IsEmpty
  • GetItem
  • PutItem
  • DeleteItem
  • CountNodes

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.

  • Create Encryption Tree

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.

  • Prompt the user for a string (the encryption key)
  • Convert the string to all lowercase letters
  • Add each character in the string to the binary tree
  • Output success to the user, along with the number of nodes in the binary tree:

“Encryption Tree created successfully with 14 nodes”

You must use the CountNotes ADT operation in this command.

  • Encrypt Message

Encrypt message performs the actual message encryption by making calls to GetItem. This menu command should do the following.

  • Prompt the user for a string (the message to encrypt)
  • Convert the string to all lower case letters
  • Call GetItem from the binary tree ADT on each character in the string
  • Concatenate the codes for each character along with the delimiter
  • Output success to the user along with the encrypted message
  • For example, with the encryption key “meet me”, the message “meet me” becomes:

“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

  • Remove Characters From a Key

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:

  • Prompt a user for a string of characters to remove
  • Convert the string to all lower case letters
  • Call DeleteItem from your binary tree ADT to remove the letters.
  • Output success to the user, along with the number of nodes in the binary tree:

“Encryption Tree modified successfully, total nodes: 12”

You must use the CountNotes ADT operation in this command.

  • Decrypt a Message

Using the binary tree and a code entered from the user, decrypt a message and output it to the user.

  • Prompt a user for an encoded message.
  • Call Traverse from your binary tree ADT on each code in the string
  • Concatenate the letters for each code character.
  • Output success to the user along with the decrypted message.
  • For example, with the encryption key “meet me” the code *!<!<!>!<<!*!< becomes:

“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.

  • Draw the binary encryption tree created for the encryption key: “meet me at the window.”
  • How many levels are in the binary encryption tree for an encryption key that contains all 26 letters of the alphabet and the ‘space’ character in the best case?
  • How many levels are in the binary encryption tree for an encryption key that contains all 26 letters of the alphabet and the ‘space’ character in the worst case?
  • What is the Big-O run-time of your program to decrypt a message in the average case in terms of the length of the encoded message? Assume the binary encryption tree is already built, the worst case scenario of binary encryption tree has not occurred, and the length of the encoded message is ‘n.’

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 support@extutorials.com

I will help you any time

Thank you very much

Attached Files

Move over [ preview ] file name to preview content in it!

Write a review

Your Name:


Your Review: Note: HTML is not translated!

Rating: Bad           Good

Enter the code in the box below:



PURCHASE SAVE
2 Tutorials 10%
3 Tutorials 13%
4 Tutorials 16%
5 Tutorials 19%
6 Tutorials 22%
7 Tutorials 25%
8 Tutorials 28%
9 Tutorials 31%
10 Tutorials 34%
add url more

9MZQASHWN73B