Question: Pseudo-random Encoder encodes a string by replacing each letter in that string with a letter selected from a pseudo-random sequence of letters (a random sequence

Pseudo-random Encoder encodes a string by replacing each letter in that string with a letter selected from a pseudo-random sequence of letters (a random sequence that can be generated deterministically). Assume the original alphabets are arranged in a table so that each letter is mapped to a number:

Table 1: Alphabet table

Letter a b c d e f g h i j k l m n o p q r s t u v w x y z
Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Using Python's random module with a seed value of 202090, the following sequence of (distinct) random numbers between 0 and 25 can be generated:

[23, 15, 25, 1, 22, 16, 8, 0, 19, 6, 12, 9, 10, 4, 24, 11, 18, 14, 21, 3, 17, 7, 20, 2, 5, 13]

With the above list, the encoding table can be created as follows:

Table 2: Encoding table using a seed value 202090

Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Code 23 15 25 1 22 16 8 0 19 6 12 9 10 4 24 11 18 14 21 3 17 7 20 2 5 13

Using Table 1 and Table 2 , any letter can be encoded as follows:

  1. Look up the letter's number in Table 1 (e.g. 'm' corresponds to number 12).
  2. Lookup the code in Table 2 (e.g. number 12 corresponds to code 10).
  3. Lookup the code back in Table 1 to get the coded letter (e.g. code 10 corresponds to letter 'k').
  4. Covert the coded letter to upper case (e.g. coded letter 'k' is converted to 'K').

In the encoding example above, the string "programming" is encoded as "LOYAOXKKTEA".

The Pseudo-random Encoder is case-insensitive. Therefore, letter 'A' is encoded the same as letter 'a'. Also, numerical digits or other characters that are not part of the Alphabet table are not encoded, i.e. they will remain as-is in the encoded string. For example, in the encoding example above, the string "ITC106: Programming Principles" is encoded as "TDB106: LOYAOXKKTEA LOTEBTLJQV".

You are required to develop a program that implements the Pseudo-random Encoder. Your program should prompt the user for an input file name and an integer number that will be used as a seed for the random number generator. After encoding the content of the input file, your program should create a file called filename-encoded.txt (assuming the input file name was filename.txt).

Review the sample run below to clearly understand the requirements.

Pseudo-Random Encoder --------------------- Enter the input file name: test1.txt Enter the seed value: 58251 File was successfully encoded and saved as "test1-encoded.txt". Have a nice day! 

The contents of the input and output files are shown below:

test1.txt test1-encoded.txt
Computers are designed to work ONLY with binary data which is formed by a sequence of binary digits (called bits). All data in a computer is stored in a sequences of 0s and 1s. Similarly, all instructions that a CPU understands are also written as bits. For example, 0000 0000 1100 0001 instruction in an Intel CPU means add two numbers. Each brand of CPU has its own instruction set. To carry out a meaningful task, the CPU must execute a long set of instructions. BYKLRDQOV XOQ WQVTAEQW DY UYOM YEJN UTDH PTEXON WXDX UHTBH TV IYOKQW PN X VQSRQEBQ YI PTEXON WTATDV (BXJJQW PTDV). XJJ WXDX TE X BYKLRDQO TV VDYOQW TE X VQSRQEBQV YI 0V XEW 1V. VTKTJXOJN, XJJ TEVDORBDTYEV DHXD X BLR REWQOVDXEWV XOQ XJVY UOTDDQE XV PTDV. IYO QCXKLJQ, 0000 0000 1100 0001 TEVDORBDTYE TE XE TEDQJ BLR KQXEV XWW DUY ERKPQOV. QXBH POXEW YI BLR HXV TDV YUE TEVDORBDTYE VQD. DY BXOON YRD X KQXETEAIRJ DXVM, DHQ BLR KRVD QCQBRDQ X JYEA VQD YI TEVDORBDTYEV.

Constraints

  1. You must define a function called create_code_list that accepts an integer value (random seed) and returns a sequence of distinct numbers with the same length as the alphabet list (code list).
  2. You must define a function called encode that accepts the original string and the code list, and returns the encoded string.
  3. You must use lists, dictionaries, and string methods in your program.
  4. You must handle the exceptions of IOError and ValueError with specific handlers. In addition, your program must not crash regardless of the input provided.
  5. Your program must not import any library or module other than the standard random module.

Task 1 (15 marks)

Implement your program in Python. Comment on your code as necessary to explain it clearly.

Task 2 (5 marks)

Select at least three sets of test data that will demonstrate the normal operation of your program; that is, test data that will demonstrate what happens when a valid input is entered. Select two sets of test data that will demonstrate the abnormal operation of your program; that is, test data that will demonstrate what happens when an invalid input is entered or when an error is encountered.

Set it out in a tabular form as follows: test data type, test data, the reason it was selected, the output expected due to using the test data, and finally a screenshot of the output actually observed when the test data is used. It is important that the output listings (i.e., screenshots) are not edited in any way.

Data type Test data Reason it was selected Expected output Screenshot of actual output
Normal
Normal
Normal
Abnormal
Abnormal

Run your program using the test data you have selected and complete the last column of test data tables above.

can you please write full program on the question basis

as It was answered before but not properly

please please please

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 Databases Questions!