Library 9
Todays exercises look like those from sessions 6 and 8.
Today you must write the tests, and then the functions.
All the solutions to the following exercises MUST
- Be written in python, and, apart from testing what they are required to test, they must
- Contain a copyright notice re the example below.
- You may work in pairs
- This time hand in as repos re the README of our materials.
Model
You MUST use the following as a model:
|
|
The file lib9.py
must be modelled after
lib8.py
and lib6.py
.
Exercise OSD.9.1
Write a function vigenE(s, key)
that encrypts
and returns a string s
with the Vigenére Cipher,
a substitution cipher where each character
is substituted with the character from another
alphabet according to a key. Please refer
to the quote of Aumasson above.
All characters MUST be converted to uppercase, punctuation and spaces must be removed. All positions will be modulo the length of the alphabets.
Example:
|
|
Exercise OSD.9.2
Write a function vigenD(key, s)
that decrypts
and returns a string s
that was encrypted with
The Vigenére Cipher re OSD.9.1.
Exercise OSD.9.3
Write a function bigram(s)
that receives a text
(string) and returns a dictionary of bigram
frequencies.
For info on bigrams pls refer to
https://en.wikipedia.org/wiki/bigram
Exercise OSD.9.4
Write a function trigram(s)
that receives a text
(string) and returns a dictionary of trigram
frequencies.
For info on trigrams pls refer to
https://en.wikipedia.org/wiki/trigram
Exercise OSD.9.5
Now based on OSD.8.3, OSD.9.3, and OSD.9.4
try to write a function n_gram(s, n)
.
The function must take s
, a string, as input
with an integer n
where n > 0
.
The function must be capable of creating
- letter frequencies re OSD.8.3,
- bigram frequencies re OSD.9.4, and
- trigram frequencies re OSD.9.4
where n
is 1, 2, and 3 respectively.