Department of Electrical and Computer Engineering
The University of Texas at Austin



EE 306 Fall 2002
Programming Assignment 3 (Assembly Language)
Due November 17, 2002 at 11:59pm

EXTRA INFO for Lab #3
1. Background
Cryptography, from the Greek word kryptos, meaning "hidden", deals with the science of hiding a message from eyes you do not want to understand the contents of the message. The desire to do this has existed ever since humankind was first able to write. There are many ways to keep something secret. One way is to physically hide the document. Another way is to encrypt the text you wish to remain secret. Some people use this to keep others from understanding the contents of the files in their computer. Encrypting a file requires an input message, called the "plain text," and an encryption algorithm. An encryption algorithm transforms "plain text" into "cipher text." Just like a door needs a key to lock and unlock it, an encryption algorithm often requires a key to encrypt and decrypt a message. Just like a homeowner can selectively give the key to the front door to only those he wants to allow unaccompanied access, the author of a message can selectively give the encryption key to only those he wants to be able to read the message. In order for someone to read the encrypted message, he has to decrypt the cipher text, which usually requires the key.

For example, suppose the plain text message is HELLO WORLD. An encryption algorithm consisting of nothing more than replacing each letter with the next letter in the alphabet would produce the cipher text IFMMP XPSME. If someone saw IFMMP XPSME, he would have no idea what it meant (unless, of course, he could figure it out, or had the key to decrypt it.) The key to encrypt in this case is "pick the next letter in the alphabet," and the decryption key is "pick the previous letter in the alphabet." The decryption algorithm simply replaces each letter with the one before it, and presto: the plain text HELLO WORLD is produced.

2. Assignment

Implement, in LC-2 assembly language, an encryption/decryption program that meets the following requirements:

Input

Your program should prompt the user for three separate inputs from the keyboard, as follows:

1. The prompt: IF YOU WANT TO ENCRYPT, TYPE E; IF YOU WANT TO DECRYPT, TYPE D:

2. The prompt: ENTER THE ENCRYPTION KEY (A SINGLE DIGIT FROM 1 TO 9):
3. The prompt: INPUT A MESSAGE OF NO MORE THAN 20 CHARACTERS. WHEN DONE, PRESS <ENTER>
Algorithm

The encryption algorithm is as follows. Each ASCII code in the message will be transformed as follows:

1. the low order bit of the code will be toggled. That is, if it is   a 1, it will be replaced by a 0; if it is a 0, it will be replaced   by a 1.

2. The key will be added to the result of step 1 above.


The decryption algorithm is the reverse. That is,

1. Subtract the encryption key from the ASCII code.
2. Toggle the low order bit of the result of step 1.


Output

Your program should output the encrypted or decrypted message to the screen. Note that the encryption/decryption algorithm stored the message to be output starting in location x3116.

Format

Your program must be a text file of assembly code (i.e., a .asm file).

For further reading on the subject of cryptography and its role in history, "The Code Book" by Simon Singh is recommended.