Program 2

Due Date: Thursday, November 3, 2005
Points: 100


This program asks you to implement the Vigenère cipher, as discussed in class.

Your program is to be called "vigenere". It should be able to both encipher and decipher text.

Input

Your program is to read text from the standard input. It takes one or two command-line arguments. If the text is to be enciphered, the single argument is the cryptographic key. If the text is to be deciphered, the first argument is to be the option "-d" and the second argument is the cryptographic key.

Output

Your program is to output the text enciphered using the key (if no option is given), or deciphered using the key (if the option -d is given).

Example

Here is an example run for enciphering (input and output). The "%" is a shell prompt: What the user types is in boldface; the output is in normal type:

% vigenere ecs
hello world
lgdpq ostdh
%

Here is an example for deciphering:

% vigenere -d ecs
lgdpq ostdh
hello world
%

Suggestions

You only need to encipher the letters. You also need to preserve case, so capital letters are transformed into capital letters and lower-case letters are transformed into lower-case letters. All other characters should be left untouched.

Extra Credit

  1. (Easy; 15 points) Allow a second option, "-b", for encryption that forces the output to be in blocks of five characters regardless of the spacing of the input. With this option, delete all non-alphanumeric characters.
  2. (Easy; 15 points) Allow the user to specify a file name on the comman line after the cryptographic key. The output should go to the standard output.
  3. (Very Difficult; 50 points) Allow the "-b" option for decryption. With this option, all non-alphanumeric input characters are ignored, and your program outputs English words. The intent is that the user can give ciphertext generated from the first extra credit version of the program as input, and produce the original plaintext.


Here is a PDF version of this document.