Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Goal: Learn to replace characters in strings. Assignment: A Caesar cipher is a method to encrypt messages by which each character in the message is
Goal: Learn to replace characters in strings.
Assignment: A Caesar cipher is a method to encrypt messages by which each character in the message is shifted by a certain amount, to the left or to the right, in the alphabet. The amount by which the characters are shifted is known as the key. For example, the letter A with a key of three to the right would be encrypted as D
On its own, a Caesar cipher is pretty easy to break. However, it still has applications today eg ROT
Write a program that reads a string of text as input, applies the Caesar cipher to said text, and displays the encrypted message to the user.
In your program, the builtin functions ord and chr will be helpful. The ord function takes a character as its argument and returns an integer code representing that character. For example,
the expression ordA returns
the expression ordB returns
the expression ordC returns
and so forth.
The chr function takes an integer code as its argument and returns the character that code represents. For example,
The expression chr returns A
The expression chr returns B
The expression chr returns C
and so forth.
Also, assume a variable named key containing the cipher's integer key has already been assigned. A negative key means the characters are shifted left, and a positive key means the characters are shifted right.
Note: Do not display a prompt for the user, just use input
Sample Run User input enclosed in
iboet!pggnznbdbspoj
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started