Project #1: Secret Decoder Ring

Submit: Turn in your encoder-ring.c and decoder-ring.c source files using the turnin command on morbius.mscsnet.mu.edu or one of the other Systems Lab machines.

Work is to be completed individually. Be certain to include your name in the file. You may submit multiple times, but only the last turnin will be kept. The automatic submission system will not accept work after the deadline. (See turnin instructional video HERE. Note that the video is for a different course number, and that Morbius's domain name has changed since the video was made: morbius.mscs.mu.edu -> morbius.mscsnet.mu.edu)

Include a comment block at the very top of each file that contains the following:

/**
 * COSC 3250 - Project 1
 * Explain briefly the functionality of the program.
 * @author [your name]
 * Instructor [your instructor]
 * TA-BOT:MAILTO [your email address]
 */

Ring of Xinu

Whenever Lord Xinu (Dark Lord of the Mips) is communicating with his minions over long distances, he uses his super-secret, Wormhole X-Treme! cereal box decoder ring to properly encipher his messages.

Your task is to write two simple programs that automate the process of enciphering and deciphering messages without relying on the cheap plastic decoder ring.

You should use the getchar library function to read console input one character at a time. The use of any other library functions for input is not recommended at this time.

We have provided example programs for your reference, executable on Morbius as ~brylow/os/Projects/encoder-ring and ~brylow/os/Projects/decoder-ring.

Simple Autokey Cipher

Autokey ciphers are a class of polyalphabetic cipher algorithms that incorporate the text of the plaintext message into the cipher key.

Envision our decoder ring as a disk with the 26 upper-case alphabet letters arrayed around its edge in order, with a 27th place between 'Z' and 'A' containing a space. Each of the 27 slots has a number associated with it: the space is 0, 'A' is 1, 'B' is 2, and so on up to 'Z' = 26.

To encipher a message, Lord Xinu first chooses a positive integer key value. His minions will use the same key value later to decode the enciphered message. Next, he adds the key value to the value of the first letter of his message, which is equivalent to counting that many slots around the edge of the decoder ring. The symbol he lands on will be the first character he sends as his encrypted message.

If Lord Xinu followed this same algorithm -- adding the key value to each letter in turn -- he would have what is called a shift cipher, such as the infamous Caesar cipher or ROT13. This is too easy to break; to make this a more difficult autokey cipher, he instead adds the next letter value and key to his current position on the decoder ring.

For example:

Assume a key value of zero, and a message of "Hello world!". The first letter 'H' has value 8. The key is 0, and there is no previous value, so 'H' will be encoded as 'H' (8 + 0 + 0 = 8 = 'H'). The second letter is 'e', which has value 5. The previous value plus 'e' plus the key is 'M' (8 + 5 + 0 = 13 = 'M' .) The third letter of the message is 'L'. (Note that we immediately convert lower-case letters to upper-case for this code.) Previous value 13 plus 'L' (12) plus key (0) = 25 = 'Y'. The fourth character is also 'L'. Previous value (25) plus 'L' (12) plus key (0) = 37, which when wrapped around the decoder ring (modulo 27) is 10, or 'J'.

The enciphered result for "Hello world!" is thus "HMYJYYUI LPP" with a key of 0, or "IOANCDAQIV A" with a key of 1, or "JQDRHJHYREKM" with a key of 2, and so on.

Newline characters ('\n') are transmitted unencoded. Note that we treat spaces -- and all other non-alphabetic characters -- as value 0. They will be decoded as blank spaces.

This assignment can be completed using simple loop and conditional constructs, along with basic integer operations like addition and modulus. Your encoder-ring and decoder-ring programs should take an optional key value as a command-line argument. (See textbook section 5.10.) If no argument is given, the key is assumed to be 0. You may use the C library function atoi (textbook section B5), or parse the command-line integer yourself. The encoder-ring reads in plaintext messages line by line and outputs ciphertext encrypted with the specified key. The decoder-ring reads in ciphertext as input and outputs the plaintext message decrypted with the specified key.

Notes


[back]

[Revised 2022 Jan 24 22:17 DWB]