Answered step by step
Verified Expert Solution
Link Copied!

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 (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

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

Question 1 (a2) What is the reaction force Dx in [N]?

Answered: 1 week ago

Question

Why is it important to match sources and methods of recruitment?

Answered: 1 week ago