Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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 prograrm wil be a string of plaintext and the value of the key. If decoding, the input to the program will be encoded text and the key value will 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: uqtrwuu Please enter a string: uqwtrwuu Please enter a key: -2 The decrypted string is: sou Please enter a string: zany Please enter a number 6 The encrypted string is: fgte Here are some hints and notes: rpuss 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 calculated as: chr (ord (ch) key) . 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 stringis:"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 key0 else "The decrypted string is

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions