Question: finish part B Part A . [ 4 mark ] Header Encoding Write a program that reads a line of printable characters and encodes with
finish part B Part A mark Header Encoding
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 s and s The sequence of keys starts with one key with length followed by three keys with length seven keys of length fifteen keys of length etc. The keys of the same length are in sequence of its binary value but not with all s
The encoding scheme is as follows.
Assume the input header is: mathbfnmathbfX# mathbf$
key string:
To verify the correctness of the encoding, write a function to read in a character and print the keys of that character.
Notes:
You may not know the length of the header in advance.
The maximum length of the key string is seven. That is the longest key string is Hint: A character string should have a backslash at the end of the string.
The header contains only printable characters including "space", ie any characters in the ASCII Table with values from to
We assume the input is valid, ie no need to check the correctness of input.
The header may have repeated characters that lead to different keys.
Sample Input and Output
Example
Enter Header:
nX# $
Enter character:
$
Example
Enter Header:
nX# $n
Enter character:
Example Part B marks Message Decoding
Extend your program in Part A to decode a message based on the keys generated in Part A The encoded message is a sequence of binary digits. The message should be decoded in segments. Each segment starts with the first digits to represent the length of keys to be decoded in the subsequent digits. The end of each segment is signified by a sequence of s of that length.
With the example header in Part A the segment would be decoded as follows.
The message may have multiple segments and ends with the binary string
Example : message segmentrightarrow decoded message mathbfX
Example : message segmentsrightarrow decoded message #$n
Your program should read in the header and an encoded message; then decode the message and output the decoded message.
Notes:
Refer to the Notes of Part A
The encoded message is assumed to be in one line.
We assume the input is valid.
Sample Input and Output
Example
Enter Header:
nX# $
Enter message:
beginarrayl
text # nX
endarray
Example
Enter Header:
: IkC
Enter message:
beginarrayl
text C
endarray
Example
Enter Header:
@A pqrstuv #$EFSTCabghrscdeieor
Enter message:
CS is a great course!
Example
Enter Header:
giOAstd!mten
Enter message:
Assignment
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
