Question: Exercise 3 : Caesar Cipher With mapper, it is straightforward to write a general function to apply a Caesar cipher across any number of letters.
Exercise : Caesar Cipher
With mapper, it is straightforward to write a general function to apply a Caesar cipher across any number of letters.
Although there are a few ways to accomplish this, most students have found it more straightforward to use mapper directly on each letter. This is more efficient for short messages. You could also ese mapper to prepare a dictionary mapping each letter, and then use the dict to map each letter as it is encoded. This is more efficient for longer messages, but seems to be too involved for the length of a lab.
Compose a function caesarcipher which accepts a string message and an integer offset. It should return message with each letter mapped by offset to another letter in the alphabet. offset should default to in the case that the user does not supply it
:
#grade
# define your function here
def caesarciphermessage offset:
# Encode the message converted to upper case Hint: use the mapper function
## YOU WRITE THIS BLOCK USE THE ABOVE CODE IF YOU NEED HELP
## Step : Convert to upper case
## Step : Encode message and add to a variable encoded
# Finally, return the encoded message.
pass
:
# test your code here. You may edit this cell, and you may use any sample text, but the following is provided for
# convenience.
text The Sign of Fear, by Arthur Conan Doyle"""
caesarciphertext
:
# it should pass this testdo NOT edit this cell
# test case with specified offset
testtext A man should keep his little brainattic stocked with all the furniture that he is likely to use, and the
rest he can put away in the lumberroom of his library, where he can get it if he wants it
codetext F RFS XMTZQI PJJU MNX QNYYQJ GWFNSFYYNH XYTHPJI BNYM FQQ YMJ KZWSNYZWJ YMFY MJ NX QNPJQD YT ZXJ FSI YMJ
WJXY MJ HFS UZY FBFD NS YMJ QZRGJWWTTR TK MNX QNGWFWD BMJWJ MJ HFS LJY NY NK MJ BFSYX NY
resulttext caesarcipher testtext,
assert resulttext codetext
print 'Success!
:
# it should pass this testdo NOT edit this cell
# test default case
testtext You know my methods, Watson."""
codetext ZPV LOPX NZ NFUIPET, XBUTPO."""
resulttext caesarcipher testtext
assert resulttext codetext
print 'Success!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
