Question
A Caesar cipher is one of the simplest and most widely known encryption algorithms. In this algorithm, each letter of the plaintext is replaced by
A Caesar cipher is one of the simplest and most widely known encryption algorithms. In this algorithm, each letter of the plaintext is replaced by a different letter that is some fixed number of positions later in the alphabet. For example, with a shift number of 4,Awould be replaced byE,Bwould becomeF, and so on.
You already created a function that produces an alphabet: createAlphabet().
import string
def createAlphabet():
"""
createAlphabet returns a string that includes
all lowercase letters,
followed by all upper-case letters,
then a space, a comma, a period, a hyphen('-'),
a tilde('~'), and a pound symbol ('#').
NOTE: the order of characters in the alphabet is
very important!
In other words, the string being returned will be
'abcdef...xyzABCDEF...XYZ ,.-~#' (the ellipses ...
hide the alphabet letters)
"""
lc = string.ascii_lowercase
uc = string.ascii_uppercase
return lc + uc + " ,.-~#"
IMPORTANT:make sure that you use createAlphabet() as the helper function to generate the alphabet used by the encryption/decryption routines. You should be able to change the alphabet returned by createAlphabet() and all your other functions should still work correctly.
- getCharacterForward(char, key) - return right-shifted character.
- char is a single character from the alphabet
- if char is not a single character, return None
- key is an integer that indicates the number of steps to take
- if key is not an integer, return -1
Upon receiving a character and a "key" this function gets the character to the right ("forward") of char in the alphabet. To do so, it looks at the index of char in the alphabet and moves forward by the number of steps specified in the key.
For example, if you call this function with parameters "b" and 2 the result will be "d". It is because "d" is 2 characters away from "b". As another example, if you call this function with the input "a" and the total number of characters (len(createAlphabet()) the result will be "a" because you move it to the number of total characters and you will eventually land on the first character that you started the process on.
def getCharacterForward(char, key):
"""
Given a character char, and an integer key,
the function shifts char forward `key` steps.
Return the new character.
If `char` is not a single character, return `None`.
If `key` is not an integer, return -1.
"""
return "stub
PLEASE ONLY USE FOR LOOP OR WHILE LOOp
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