Question: Assignment 1 A Caesar cipher is a simple substitution cipher based on the idea of shifting each letter of the plaintext message a fixed number

 Assignment 1 A Caesar cipher is a simple substitution cipher based

Assignment 1 A Caesar cipher is a simple substitution cipher based on the idea of shifting each letter of the plaintext message a fixed number (called the key) of positions in the alphabet. For example, if the key value is 2, the word "sourpuss would be encoded as "uqwtrwuu" The original message can be recovered by "reencoding" it using the negative of the key. Write a program that can encode and decode Caesar ciphers. If encoding, the input to the program will be a string of plaintext and the value of the key. If decoding, the iput to the program will be encoded text and the key value wl be the negative of the original key. Here are some sample runs of the program: Please enter a string: sourpuss Please enter a key: 2 The encrypted string is: uqutrvuu Please enter a string: uqutrvuu Please enter a key -2 The decrypted string is: sourpuss Please enter a string: zany Please enter a number: 6 The encrypted string is: fgte Here are some hints and notes: You can assume that all the letters used are lower case. if ch is a character in the string and key is the amount to shift, then the character that replaces ch can be caleulated as: chr (ord (chkey). One additional case to worry about is when we "drop off the end" of the alphabet. A true Caesar cipher does the shifting in a circular fashion where the next character after "z" is "a." You can make your solution circular by doing some arithmetic and using the modulus operator %. For the output, you want your message to start with The encrypted string is: "if the key is positive and with The decrypted string is: if the key is negative. One way to this is to use the following snippet: s "The encrypted string is if key>0 else "The decrypted string is

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!