15292
SPRING 2020
|
Due: Monday, February 10 by 9:00AM
In World War II, the Germans used a device called an Enigma machine to encode messages that should be delivered to soldiers on the field. The beauty of this machine is that as each letter in the message is encoded to another letter, the encoding function changes, so the same letter later in the message would not necessarily be encoded the same way. Eventually, the machine's operation was discovered by the Allies, and they were able to decode the messages and learn what the Germans were planning to do. Alan Turing, considered the father of computer science, played a major role in determining how to crack the Enigma code and designing a machine called the Bombe to automate the process.
We will use a simplified machine with no plugboard, two rotors and a reflector as shown in this initial configuration below:
Rotor I
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
O
B
D
F
H
J
A
C
P
R
T
X
V
Z
N
Y
E
I
W
G
L
K
M
U
S
Q
Rotor II
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
A
J
D
K
S
I
R
U
X
B
L
H
W
T
M
C
Q
G
Z
N
P
Y
F
V
O
E
Reflector
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Y
R
U
H
Q
S
L
D
P
X
N
G
O
K
M
I
E
B
F
Z
C
W
V
J
A
T
Here's how this simplied machine works to encode the letter G as the first letter of the message.
1. We start by rotating Rotor I one position (letters shift left one position, with the first letter rotating to the last position):
Rotor I
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
B
D
F
H
J
A
C
P
R
T
X
V
Z
N
Y
E
I
W
G
L
K
M
U
S
Q
O
Important Note: After every 25 letters have been converted, the next letter rotates both Rotor I and Rotor II when it is converted. (For example, the 26th and 52nd letters will rotate both Rotor I and Rotor II.) The Reflector never rotates. Be careful, this is where most people slip up on this assignment.
2. Now use Rotor I to convert the G to a C:
Rotor I
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
B
D
F
H
J
A
C
P
R
T
X
V
Z
N
Y
E
I
W
G
L
K
M
U
S
Q
O
3. Next, the C is converted using Rotor II to D:
Rotor II
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
A
J
D
K
S
I
R
U
X
B
L
H
W
T
M
C
Q
G
Z
N
P
Y
F
V
O
E
4. Next, the D is reflected by the Reflector to H:
Reflector
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Y
R
U
H
Q
S
L
D
P
X
N
G
O
K
M
I
E
B
F
Z
C
W
V
J
A
T
5. Now we use Rotor II backwards to convert the H to L:
Rotor II (used in reverse)
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
A
J
D
K
S
I
R
U
X
B
L
H
W
T
M
C
Q
G
Z
N
P
Y
F
V
O
E
6. Finally we use Rotor I backwards to convert L to T:
Rotor I (used in reverse)
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
B
D
F
H
J
A
C
P
R
T
X
V
Z
N
Y
E
I
W
G
L
K
M
U
S
Q
O
So in our example, the original character is encrypted from G to T as follows:
G → C → D → H → L → T
Assignment
Write a computer program that asks the user for an input message to encode in all CAPS and the encode it using the Enigma procedure described above and output the result. Follow the sample runs below for full credit. Your program needs to only convert one message. We will run it multiple times to convert all of the messages. You may assume your machine always starts with the initial configuration shown at the start of the example above (before the first rotation). Note that if you run the program again and input the encoded message, you should get the original message back as the output. Each run of your program will convert ONE message only.
Here are some sample runs for you to use:
Run 1: Input message (all caps, no spaces or punctuation): A Encoded message: Q Run 2: Input message (all caps, no spaces or punctuation): Q Encoded message: A Run 3: Input message (all caps, no spaces or punctuation): AA Encoded message: QI Run 4: Input message (all caps, no spaces or punctuation): AAA Encoded message: QIU Run 5: Input message (all caps, no spaces or punctuation): QIU Encoded message: AAA Run 6: Input message (all caps, no spaces or punctuation): JAVA Encoded message: BILE Run 7: Input message (all caps, no spaces or punctuation): CLASS Encoded message: WXUHY Run 8: Input message (all caps, no spaces or punctuation): PUBLICSTATIC Encoded message: RJFWUYGJMNUM Run 9: Input message (all caps, no spaces or punctuation): PRIMITIVETYPE Encoded message: RDTOUHTPQNKFO Run 10: Input message (all caps, no spaces or punctuation): JAVAJAVAJAVA Encoded message: BILETGDWHSBU Run 11: Input message (all caps, no spaces or punctuation): COLLECTIONOFOBJECTS Encoded message: WQVWQYIKUTCPEMZROED Run 12: Input message (all caps, no spaces or punctuation): PUBLICSTATICVOIDMAINSTRINGARGS Encoded message: RJFWUYGJMNUMRWOPGYYAEEBOHEUYTF Run 13: Input message (all caps, no spaces or punctuation): ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ Encoded message: QVQQQQSSSVYRADIDDDDFFFILEFUPWURIQAUQQBSHCJHEVDNHDDOUIMDTWUMCZD Run 14: Input message (all caps, no spaces or punctuation): QVQQQQSSSVYRADIDDDDFFFILEFUPWURIQAUQQBSHCJHEVDNHDDOUIMDTWUMCZD Encoded message: ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJOf course, when we test, we will use additional messages.
You are allowed to use Python, Java, or C for your code. You should include a README.txt file that gives instructions on how to compile, run, and interact with your program.
Zip up all files that are required to run your program and hand in to Autolab (on andrew). You do not need to hand in any library files that are standard to the language you are using. If you're not sure, ask your teaching assistant.
Assignments will be graded out of 100 points. For maximum credit (100 points), your code must not only work correctly but must also be designed well, using functions for common operations to make the code as compact as possible.
Programs may be handed in up one lecture late with a 20% penalty.