[Optional Extension] Assignment 2 - Keeping Secrets

Due: Friday, January 24, 2020, at the start of class

This assignment is completely optional. If you receive at least 80% of the points, you will gain one extra late day. If you receive at least 50% of the points (but not quite 80%), you will gain half of an extra late day.

You may work alone or with a partner, but you must type up the code yourself. You may also discuss the assignment at a high level with other students. You should list any student with whom you discussed the assignment, and the manner of discussion (high-level, partner, etc.) in a readme.txt file that you include with your submission.

You should submit your assignment as a .zip file on Moodle.

Parts of this assignment:

Problem 1: The enigma of decryption

In this problem, you will write a program that can decrypt your enigmatic Caesar cipher. Your program should ask the user for the number used to seed the random library, as well as the encrypted message. It should output the original plaintext. You should save your code in a file called enigmaticCaesarDecrypter.py.

Here is an example:

Please enter a string to encrypt: apple banana CAT DOG elephant FISH GiRaFfe
Please enter a pseudo-random seed (an integer): 111

The encrypted message is:
gQgvaExskulnervewKOMAWvaUDskNYSNHClcpRgfXo
Please enter a string to decrypt: gQgvaExskulnervewKOMAWvaUDskNYSNHClcpRgfXo
Please enter a pseudo-random seed (an integer): 111

The decrypted message is:
apple banana CAT DOG elephant FISH GiRaFfe

(Hint: To make this work, you should think very carefully about how your encryption program chooses each key, before doing any coding for this problem. You will effectively want to retrace that program’s steps, decrypting the message as you go. It also might help to think about how decryption works with your simple or circular Caesar ciphers.)

Problem 2: Encrypting multiple messages at once

In this problem, you will extend your circular Caesar cipher to allow you to encrypt multiple messages from a single user input. You should start with your previous circular Caesar cipher code, and save this new program as circularCaesarExtension.py.

Here is an example:

Please enter a sequence of messages to encrypt, separated by commas: apple,banana,CAT,DOG,elephant,FISH,GiRaFfe
Please enter a key to shift by (an integer): 40

The encrypted messages are:
OccZS
POaOaO
pnG
qBt
SZScVOag
svFu
tWEOsTS

Your program should ask the user for the sequence of messages, separated by commas. After encrypting each plaintext message, you should print them out, one per line.

This example of a “nested” for loop might be of use to you:

>>> words = ["apple", "banana", "cat", "dog", "elephant"]
>>> for word in words:
	print(word)

apple
banana
cat
dog
elephant
>>> for word in words:
	print("Word:", word)
	for ch in word:
		print(ch)

Word: apple
a
p
p
l
e
Word: banana
b
a
n
a
n
a
Word: cat
c
a
t
Word: dog
d
o
g
Word: elephant
e
l
e
p
h
a
n
t

(Hint: For each message in the input (separated by commas), for each character in the message, you want to encrypt that character. Once you have all of the characters in the encrypted message, you want to store the result in some sort of data structure that keeps track of many things, and then move on to the next plaintext messsage to encrypt. After you’re done, for every message you encrypted, you want to print the encrypted message.)

What you should submit

You should submit a single .zip file on Moodle. It should contain the following files:

  • readme.txt (collaboration statement listing collaborators and form of collaboration)
  • enigmaticCaesarDecrypter.py (problem 1)
  • circularCaesarExtension.py (problem 2)