Due: Friday, April 24th at 11:59pm CDT
Submit: Turn in your source file using the
turnin command
on a
Systems Lab machine. Please name your file "main.c". Failure to follow this simple convention will cause TA-Bot
to fail.
Remember, the turnin command (to submit your file) will look like this:
turnin -c cosc2200 main.c
Work may be completed in teams of two. The names of both partners
must appear in a comment block at the top of your file for credit to
be given. I
strongly recommend that you take the time to meet
with your partner in person and work together on these projects,
rather than work separately and try to integrate at the last minute.
Use the command hook "
TA-BOT:MAILTO" in a comment in your
source files to designate mail addresses for TA-Bot output.
This UNIX tutorial may be of some
assistance.
- Login to a lab machine, and change to a fresh working directory for Homework 8.
- The ARM playground has been updated to include a template C file for this cipher assignment. Execute the the following command to get a new playground:
   tar xvzf ~pmcgee6/cosc2200/pi3Playground.tgz
Note: you can find the old ARM Assembly playground in the same directory, named oldPlayground.tgz.
I have provided a reference implementation on Morbius under ~pmcgee6/cosc2200/bin/cipher-example. Execute arm-console in this directory to run the reference implementation on a backend machine.
The Symmetric Key Block Cipher
Write a C program for the ARM Playground (still running on the Pi 3's) that enciphers input text by XORing the lower four bits of alphabetic characters with a variable length, hexadecimal key value. By running the cipher program a second time with the same key, inputting the cipher text should reproduce the original message.
Notes:
- Automatically transform lower case letters to uppercase before enciphering.
- The key value consists of 0 to 10 hexadecimal digits, or nibbles, entered before the message to be enciphered. Each successive nibble in the key is XORed with the lower nibble of the character bytes in the message. When the end of the key is reached, begin again with the first key digit.
- The cipher should leave unchanged any numbers, whitespace or punctuation marks aside from the six symbols listed below. This isn't a good property for a secure cipher to have, but makes this assignment simpler to implement and test.
- Each time a newline is seen in the message, reset the key to the first digit again. This, too, is not a good property for a secure cipher to have, but will make testing much easier when you accidentally mistype enciphered messages.
- This cipher system will transform most alphabet letters into another letter. However, because we're XORing the lower bits, it is also possible with certain key values to get one of the six punctuation marks adjacent to the upper case letters in the same block of 32 ASCII values. These symbols are: @[\]^_. Therefore, your program should also accept and encipher these six symbols, to ensure that messages can be properly deciphered.
This encryption scheme is technically a simple form of symmetric key block cipher. It would be a much stronger encryption algorithm if the key value were chosen through a pseudorandom process, and if the key was as long as the message text, making it a one-time pad. This is probably good enough to send messages by cereal box, however. As a design note, this algorithm depends on an underlying character representation in ASCII, or at least the ASCII subset of UTF8/Unicode. That means that this C code may not port over to a system that used a different character encoding scheme.
Example Run
In the examples below, I use text in blue to distinguish the output of the program from the input I typed. This is for purpose of clarity only; your program will not print text in different colors.
Cipher Generator
Enter Key Value:
01234
01234
Message:
TIG
QTK@O
BSMTJ
FNZ
JTOSAD MUAR
TIG HA[[
YDNOKW
DNE!
THE
QUICK
BROWN
FOX
JUMPED OVER
THE LAZY
YELLOW
DOG!
Note: Ctrl+D is the final input in the example.