-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Problem 1 - Build the Shift Dictionary and Apply Shift
The Message
class contains methods that could be used to apply a cipher to a string, either to encrypt or to decrypt a message (since for Caesar codes this is the same action).
In the next two questions, you will fill in the methods of the Message class found in ps6.py according to the specifications in the docstrings. The methods in the Message class already filled in are:
__init__(self, text)
- The getter method
get_message_text(self)
- The getter method
get_valid_words(self)
, notice that this one returns a copy ofself.valid_words
to prevent someone from mutating the original list.
In this problem, you will fill in two methods:
- Fill in the
build_shift_dict(self, shift)
method of theMessage
class. Be sure that your dictionary includes both lower and upper case letters, but that the shifted character for a lower case letter and its uppercase version are lower and upper case instances of the same letter. What this means is that if the original letter is "a" and its shifted value is "c", the letter "A" should shift to the letter "C".
If you are unfamiliar with the ordering or characters of the English alphabet, we will be following the letter ordering displayed by string.ascii_lowercase
and string.ascii_uppercase
:
>>> import string
>>> print(string.ascii_lowercase)
abcdefghijklmnopqrstuvwxyz
>>> print(string.ascii_uppercase)
ABCDEFGHIJKLMNOPQRSTUVWXYZ
A reminder from the introduction page - characters such as the space character, commas, periods, exclamation points, etc will not be encrypted by this cipher - basically, all the characters within string.punctuation, plus the space (' ') and all numerical characters (0 - 9) found in string.digits.
- Fill in the
apply_shift(self, shift)
method of theMessage
class. You may find it easier to usebuild_shift_dict(self, shift)
. Remember that spaces and punctuation should not be changed by the cipher.
Task of #39