Question: Write a program that reads a line of printable characters and encodes with a sequence of keys with each key is a binary string

Write a program that reads a line of printable characters and encodes with a sequence of keys with each key Example 2 Enter Header: n(X+# $90

Write a program that reads a line of printable characters and encodes with a sequence of keys with each key is a binary string of '0's and '1's. The sequence of keys starts with one key with length 1, followed by three keys with length 2, seven keys of length 3, fifteen keys of length 4, etc. The keys of the same length are in sequence of its binary value but not with all '1's. The encoding scheme is as follows. Assume the input header is: n(X+# $90\"? # $90\ ? 000 001 010 011 100 101 110 0000 n + key string: 0 00 01 10 11 To verify the correctness of the encoding, write a function to read in a character and print the key(s) of that character. Notes: 1. You may not know the length of the header in advance. 2. The maximum length of the key string is seven. That is, the longest key string is "1111110" Hint: A character string should have a "\0' at the end of the string. $ 010 *** Sample Input and Output Example 1 Enter Header: n(X+# $90\"? Enter character: 3. The header contains only printable characters including "space", i.e. any characters in the ASCII Table with values from 32 to 126. 4. We assume the input is valid, i.e., no need to check the correctness of input. 5. The header may have repeated characters that lead to different keys. Example 2 Enter Header: n(X+# $90\"?n Enter character: n 0 0001 Example 3 Enter Header: n(X+# $90\"? Enter character 001 input here is a "space"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!