Question: 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 (e.g., ROT13).
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 built-in 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 ord('A') returns 65
the expression ord('B') returns 66
the expression ord('C') returns 67
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(65) returns 'A'
The expression chr(66) returns 'B'
The expression chr(67) 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!pgg!nz!nbdbspoj

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!