Q1: Finding the Key
Background
It has been rumored that professor Dan has a reading level of a
5 year old. Being embarrassed of this, he keeps his books encrypted
so that others cannot find out what he is reading. You somehow
stumble into his book library and discover the encrypted books.
Since you took a class with Dan, you want to discover if the rumour
is true.
We define the encrypted text as the text that is
encrypted and therefore not currently readable. We define the
plaintext as the text that was encrypted.
Remember the Caesar Cipher that we worked on in Week 3? After
some investigation, you realize that Dan has used a Caesar Cipher
to encrypt each book.
As a reminder, Caesar Cipher is an encryption technique in which
each letter of the plaintext is shifted by a certain number of
characters. The encrypted text can be decrypted by shifting in the
opposite direction.
In Week 3, we used a shift value of 3. Here, Dan has chosen his
own shift value for each book.
You need to decrypt Dan’s books to figure out what he is reading
and confirm/deny the rumour.
Your Task
You will write a function that can be used to decrypt Dan’s
encrypted text. You will be given an open file that
contains an encrypted passage from one of the books, and the
name of a file containing a wordlist of English words. You
need to discover the shift value to use (0-25) in order to decrypt
the text. A correct shift value is one that leads to the maximum
number of words being found in the English list of words.
To find the words in the encrypted text, you must call split().
For a given shift value, convert all letters to lowercase, then try
to find each word in the English wordlist. Do not remove any
punctuation or symbols from the word: for example, if the word is
hello!, then that is the exact string, including exclamation mark,
that you should try to find in the English wordlist.
Your function should return a string where all letters are in
lowercase, and all other characters (newlines, spaces, punctuation,
etc.) are retained.
Input
In each test case, we will call your decrypt function with an
open file that contains encrypted text, and the name
of a file containing an English wordlist.
An encrypted file contains the encrypted text; for example, it
might look like this:
An English wordlist has one word per line; here is a small
example:
Return Value
Using the full English wordlist provided in the starter code,
your function would return the following string for the above
encrypted text:
Starter code
Please find your starter code and test examples in MarkUs.
In decrypt.py, you’ll find a function named decrypt whose
implementation you must complete.
Testing
We have a thorough set of tests on which we’ll run your code.
Everything we’ll test has been discussed here and in the starter
code, so please read both carefully!
The starter code includes the test case from this handout that
you can try out by running test_decrypt.py. We have also provided
several txt files that you can use to test as well.
F.A.Q.
Can there be duplicate villager names or song
names?
No.
What happens if there are multiple bards at a
party?
Only one of them sings. It doesn’t matter which one, since they
would all choose the same next song.
What happens if there are only bards at a
party?
Whether anyone sings or not makes no difference since all the bards
already know all the songs.
What happens if there are no new songs for a bard to
sing?
The party is boring. No one sings. Nothing changes.
What happens if a party has no bard, but during the
party a villager learns enough songs to become one?
A villager can only become a bard at a party that already has a
bard, so this can’t happen. A party either has a bard at the
beginning or doesn’t, and a party’s status never changes once it’s
begun.
If there’s a party where a villager learns enough songs
to become a bard but there isn’t a bard at the party, do they miss
their chance?
No, they become a bard at the next party they attend where there’s
a bard (if they ever attend such a party).
Sets
One of the concepts you’ll be practicing throughout this
assignment is sets.
A set is very much like a list, with a few differences:
Sets have their own set of operations as described in
set theory. You may find set union and set
difference useful and, in general, you will find sets a valuable
tool throughout this assignment.
Important Reminders
Q1: Finding the Key Background It has been rumored that professor Dan has a reading level of a 5 year old. Being embarra
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am