15-110 Spring 2011
Recitation 5
- No quiz this week
Next week's quiz will cover hw3.
- Schedule small-group sessions
Your CA will discuss this with you in recitation today.
- Starter code:
Here is the starter code for this week's recitation:
recitation5.py
- Caesar Cipher
Write an encoder and decoder for a simple Caesar cipher (see the Wikipedia page on Caesar ciphers).
Variants of this cipher were commonly used in the time of Caesar,
though it is not used anymore, because it is too easy to crack.
This cipher rotates all uppercase letters by a given "shift" amount. If
the shift is 3, for example, "A" becomes "D", "B" becomes "E", and so
on. The cipher wraps around, so "W" becomes "Z", but "X"
becomes "A", "Y" becomes "B", and "Z" becomes "C". To keep things
simple, include non-uppercase letters as they are. The encoder takes a
plaintext string, along with the shift size, and returns the
ciphertext (encoded) string. The decoder works in reverse, taking
the ciphertext string, and the shift size, and returns the original
plaintext.
- Vigenere-Like Cipher
Write an encoder and decoder for a simple Vigenere-like cipher (see the Wikipedia page on Vigenere ciphers).
This works like a Caesar cipher, only instead of using a single shift
for all letters, the shift varies letter by letter. To indicate
the shifts in a real Vigenere cipher, the encoder or decoder provides a
passphrase composed of only uppercase letters. Here, instead, we
will use a list of integers, which we will call the shiftList. If the
shiftList is [3, 5, 2], then the first character is shifted 3, the
second one 5, the third one 2. But now what? At that point,
we wrap around our shiftList and continue, so the fourth character is
shifted by 3. Also, to make this usable as a true Vigenere
cipher, add a helper function called makeShiftList that takes a
string of uppercase letters and returns the corresponding shiftList.
- isMagicSquare
A
2d list of integers is a magic square if it is actually square (same
number of rows and columns) and every row, every column, and both
diagonals all sum to the same value. For more, see the Wikipedia page on Magic Squares.
Write the function isMagicSquare that takes a 2d list of integers and
returns True if it is a magic square and False otherwise.
- Sample Solutions
Here are sample solutions for this week's recitation:
recitation5-solutions.py