# 15292 History of Computing

SPRING 2017

HOME | COURSE INFO | SCHEDULE & EXAMS | LECTURES | ASSIGNMENTS | RESOURCES

# COMPUTING ASSIGNMENT 2

### ASSIGNMENT

Due: Friday, February 10 by 10:30AM

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.

Here's how the machine works (this is a slightly simplified version - based on information provided HERE).

1. We start with Table I that shows how to encrypt the original character:

Table 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

For example, if the original character is G, this table shows that it should be converted to C.

2. Next, the converted character is used in Table II for another encryption:

Table 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

For example, the converted character C from Table I would then be converted into a D using Table II.

3. Next, the converted character from Table III is converted using Table III, which is a "reflector" table that is set up so that if x converts to y then y converts to x:

Table III
 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

For example, the converted character D from Table II now gets converted into an H. (Note that H also converts back to a D in the table since the table is a "reflector".)

4. Now we use Table II backwards to further encrypt the character. Table II is now used as an inverse function, so we start with a character along the bottom row and encrypt to a character along the top row.

Table 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

For example, the H that comes from Table III is now encrypted to an L using Table II in reverse.

5. Finally we use Table I backwards to further encrypt the character. Table I is used as an inverse function also, so we start with a character along the bottom row and encrypt to a character along the top row.

Table 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

For example, the L the comes from Table II (in the previous step) is now encrypted to a T using Table I in reverse.

So in our example, the original character is encrypted from G to T as follows:

G --> C --> D --> H --> L --> T

6. Before the next letter in the message is encrypted, the bottom row of Table I is shifted to the left one position, with the first letter in the bottom row wrapping around to the last letter in the bottom row:

Table I (after rotation)
 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 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 B

If this rotation causes Table I to return to its original starting point, Table II's bottom row is rotated one position to the left (with wraparound) as well. Table III never rotates.

(THINK: How many times does Table 1 have to rotate before it gets back to its original starting point?)

Write a computer program that asks the user for an input message to encode and the encode it using the Enigma procedure described above and output the result. Note that if you run the program again and input the encoded message, you should get the original message back as the output. Here are some sample tests for you to use:

```      Message 0: A
Encoded message: Q

Message 1: Q
Encoded message: A

Message 2: AA
Encoded message: QI

Message 3: AAA
Encoded message: QIU

Message 4: QIU
Encoded message: AAA

Message 5: JAVA
Encoded message: BILE

Message 6: CLASS
Encoded message: WXUHY

Message 7: PUBLIC STATIC
Encoded message: RJFWUY GJMNUM

Message 8: PRIMITIVE TYPE
Encoded message: RDTOUHTPQ NKFO

Message 9: JAVA JAVA JAVA
Encoded message: BILE TGDW HSBU

Message 10: COLLECTION OF OBJECTS
Encoded message:  WQVWQYIKUT CP EMZROED

Message 11: COMPARABLE OBJECTS MUST HAVE A COMPARETO METHOD
Encoded message:  WQXBOXNNYO CNYCMFE QGMD BGHY P QIFWUHHNE ZXNFYF

Message 12: PUBLIC STATIC VOID MAIN(STRING ARGS)
Encoded message:  RJFWUY GJMNUM RWOP GYYA(EEBOHM UYTF)
```
Of course, when we test, we will use additional messages.

### EMBELLISHMENTS

You may add additional features to this program to simulate the machine more directly. Examples might include:

• Allowing the user to input the letter sequences for the rotor wheels and reflector wheel before asking for the input message so any machine setting can be tested.
• Including the patch cable feature of the Enigma machine.
• Creating an animation that shows the encryption of characters.
• ...something else that will make us say "nice!"...

Embellishments that show significant skill will be awarded additional points and may be presented in class.

### OTHER FACTORS

You are allowed to use Python, Ruby, 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), we expect that your program will contain one significant embellishment beyond the basic requirements of the assignment. Assignments that meet the basic requirements will receive 90 points.

Programs may be handed in up to 24 hours late with a 20% penalty.

Special thanks to Margaret Reid-Miller for the description and examples of the Enigma Machine.