Question: Write a function updown encrypt() that takes the following arguments, in this order: Please use python to solve the problem. Part I: The Up/Down Cipher:
Write a function updown encrypt() that takes the following arguments, in this order: Please use python to solve the problem.
Part I: The Up/Down Cipher: Encryption Algorithm (20 points) Write a function updownencrypt that takes the following arguments, in this order: . plaintext: a plaintext string containing lctters, digits and spaccs that will be encrypted num rows: the number of rows that will be used in the encryption process Here's how the up'down cipher works. First, take a plaintext string and start drawing characters from it, placing the first num rows of characters into the first column of a grid from up to down. We assume here that the grid has numrows rows in it. Then take the next num.rows characters, placing them into the second column of the grid in reverse order, Irom down to up. Continue in this lashion, drawing characters Irom the plainlext string until you rum oul ol characlers, allernaling belween placing Ihem from up-lo-down anddwn-lo-up. With some arithmelic CSE 101 -Fall 2017 Page 1 you should be ahle to figure out exactly how many columns your grid will need to store all the characters from plaintext. As an cxample, suppose we want to cncrypt the string ABCDEEGIII JKIMNOPORSTUVW with num.rows - 5. The characters would be placed into a grid as follows (the arrows indicate the direction that the letters are written to the grid): AJKTU RTT.SV CHMR DGNO EFOP If all characters from the plaintext are placed into the grid but the last column is incomplete, we fill the last column with % symbols: BILSV CHMRW Next, take cach ow of characters, from left to right, and concatenate them to gencrate the final, cnerypted slring. lor the example ahove, the linal encrypled siring would he: AJKTUBILSV +CHMRDGNG RPOP\ = AJKTURTT.SVCHMRWDGNOER.ROP%. Here's anotber example: plaintextSTONYRRCOKUNTV num rows- Insert the characters into the grid TRK NYNI Insert t symbols into the last column, as necessary Soot OBUV NYNT Concatenate the rows of characters together to generate the final, encrypted string: S003TRKROBUVNYNI Note: num.rows must he grealer tha e. In the c ha num.rows 0, your function should relurn plaintext. In the casc thatplaintext is an cmpty string. your function should rcturm a string of num.xows CSE 101-Fall 2017 Homework #4 Page 2 symbols. Examples: Function Call updown encrypt AMERICA' updowenctypLSTONYBROOKUNIV', 4) Return Value AMERICA 004 TRIGODUVNYNT , down encrypt ( CHICKENWINGS, -2) HICKENWINGS
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
