Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is python question. please follow the restrictions. This is python question. please follow the restrictions. This is python question. please follow the restrictions. at

This is python question. please follow the restrictions.

This is python question. please follow the restrictions.

This is python question. please follow the restrictions.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

at Tools Add-ons Help Last edit was 12 minutes ago rmal text Arial 9.5 + E = 15 III = 1 2 1 1 1 1 2 3 1 4 1 5 61 711 8 1 9 1 10 11 12 1 13 14 | 15 | 16 | 17 18 RESTRICTIONS Only allowed: variables, if statements, while loops. Functions: ord(), chr(), len(), int(), float(), type (), isinstance(), abs (). String methods: format(), isalpha(), lower (), upper (). List operators and methods: create [ ], list(), append(). File operators: open(), close (), read(), readlines (). Keywords: elif, else, return, break, continue, def, self, None, try, raise, except, finally, is, import sys. Any exception handling. Remember: Do NOT use for loops or the in keyword. Do NOT use min () /max (), enumerate()/zip() or sorted(). Do NOT use negative indexing (e.g. 1s[-1]) or slicing (e.g. (1:1). Do NOT use any other list operations or string methods. Marks will be deducted. You may write additional helper functions if you wish. Write a program bespokkle.py that implements the cipher for case insensitive text. Your program will be run using $ python3 bespokkle.py . This program will open a file containing plaintext characters, convert the input text to lowercase and then perform the encryption operation using the two keys. The encryption operation will first create an arrangement of the alphabet in a 2D layout according to keyl. Next, for each input character, it will find the output character using key2 as the adjacent cell choice from the 2D layout derived in the first part. . key1 should be any integer between 2 and 25 inclusive. key2 should be any integer between 0 and 8 inclusive. Any numbers or punctuation in the plaintext should not be encrypted. Hint: Refer to the ord() and chr() functions as they will be helpful for this problem Keys keyi defines the number of columns in the layout of the alphabet. Here is an example of key1 =7 abcdefg hijklmn opqrstu vwXY ZAB The last few characters are upper cases characters beginning from A. Here is an example of key1 =12 abcdefghijkl mnopqrstuvwx yzABCDEFGHIJ Here is an example of key1 =13 abcdefghijklm nopqrstuvwxyz key2 defines the what will be the new output character for the input character. It is based on the alphabet layout using key1. The cell layout numbers are as follows: 123 405 678 Single case example Consider the input text file containing the single word last column layout key1=7 cell choice key2=3 First, convert all characters of the input text to lowercase (leaving special symbols and numbers as they are) Second, create the layout abcdefg hijklmn opqrstu VWXYZAB Third, visit each character and derive its output The first character is l Look at the layout and the adjacent cells ...def. ...klm. ...rst. Now consider the numbering, notice key2=3 , it is the upper right corner ...123. ...405. ...678. As key2=3 , we change the input letter 1 to the output letter f In the word last, the second character is a Look at the layout and the adjacent cells for this letter: ab....8 hi....n vw....B Notice that a sits on the corner. It has adjacent cell numbering: 05....4 78....6 23....1 The numbers wrap around to the other side of the layout. As key2=3 , we change the input letter a to the output letter w In the word last, the third character is s Look at the layout and the adjacent cells for this letter: ...klm. ...rst. ... yZA. Notice that s also includes A in its adjacent cells. It has adjacent cell numbering: ...123. ...405. ...678. As key2=3 , we change the input letter s to the output letter m In the word last, the fourth character is t Look at the layout and the adjacent cells for this letter: .... lmn ..stu .... ZAB t has adjacent cell numbering: ....123 ....405 ....678 As key2=3 , we change the input letter t to the output letter n The output of this example program is fwmn Error cases These error cases should be tested in the program in the order presented here. When there are less arguments, the last line printed should be: Not enough arguments and exit the program with return code i If any of the keys are not integers, the last line printed should be: Could not convert keys to integers and exit the program with return code 2 If key1 is outside the expected value range, the last line printed should be: keyl invalid value and exit the program with return code 3 If key2 is outside the expected value range, the last line printed should be: key2 invalid value and exit the program with return code 4 If the file cannot be opened, the last line printed should be: Could not open file and exit the program with return code 5 More examples key1=7, key2=3 t01.in last t01.out fwmn t02.in Last57 t02.out fwmn57 t03.in This gate will last a long time. t03.out nbcm vwnA qcff fwmn w fiav ncgA. key1=12, key2=6 t04.in last t04.out wxDE t05.in Last57 t05.out wxDE57 t06.in This gate will last a long time. t06.out EstD rxEp HtwwwxDE x wzyr EtJp. key1=2, key2=1 t07.in This gate will last a long time. t07.out qehr fzqd vhii izrq z inkf qhld. Notes You do not have to perform decrypt operations. All output should be printed to stdout and should not contain any unexpected data. Use stderr for any debugging print you may have planned. sys.stderr.write() Write all your entire program in the single file. You may create helper functions, but cannot import from other files

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics And Quality Management Fundamental Tools

Authors: Joseph Nguyen

1st Edition

B0CNGG3Y2W, 979-8862833232

More Books

Students also viewed these Databases questions

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago