UMBC CS 201, Spring 00
UMBC CMSC 201 Spring '00 CSEE | 201 | 201 S'00 | lectures | news | help

CMSC 201
Programming Project Four
Cryptography

Due Date: Before Midnight, Tuesday, 4/25/00

The Objective

The objective of this assignment is to give you practice using command line arguments, pointers, files, characters and strings. You will be required to write functions that have pointers as arguments

The Background

Cryptography is the science of encoding and decoding messages. Encoding a message changes the message so that only the sender and receiver of the message can understand it. If the message is seen by anyone else, it will be unreadable. The sender "encodes" the message, the receiver "decodes" the message.

A simple encoding method is letter substitution. Each alphabetic character in the message is replaced with different letter from the alphabet. For example, we might substitute the letter that comes next in the alphabet. Then each 'a' would be replaced with a 'b', each 'b' with a 'c', and so on. The letter 'z' would be replaced with an 'a'. Using this scheme, the word "help" would be encoded as "ifmq". Any characters which are not alphabetic are not translated.

Both the sender and receiver must know how to translate the characters.

The Task

Your task is to write a program that encodes and decodes files of text using simple letter substitution.

Your program will accept one command line argument which is the name of the file that contains the translation table for encoding and decoding with letter substitution. The file is described in more detail below.

Your program will present a menu to the user with the following choices

E - Encode a file D - Decode a file T - Print the translation table Q - Quit When the user chooses to encode a file, your program will prompt the user for the name of the file to be encoded and the name of the output file into which the encoded message is written. Your program will display both the original message and the encoded message to the user. The number of characters which were translated and the total number of characters processed are reported when the enctyption is finished.

When the user chooses to decode a file, your program will prompt the user for the name of the file to be decoded. Your program will display both the encoded and decoded message. As for encryption, your program will report the number of characters translated and the total number of characters processed.

To print the translation table, show which letter is substituted for every letter of the alphabet.

When the user quits, your program will report the total number of files encoded/decoded, the total number of characters processed in all files and the total number of characters translated in all files.

See the sample output below for details.

Project Requirements

  1. In this project, your code MUST include the following functions. You MAY NOT change the function prototypes in any way. A good design will require other functions as well.
  2. Only alphabetic characters should be translated. UPPERCASE characters must be encoded and decoded as UPPERCASE. Lowercase characters must be encoded and decoded as lowercase. All other characters, including punctuation and spaces must be unchanged when encoded or decoded.
  3. Your program must accept both uppercase and lower case input for the menu selection. You must validate menu choices as in project 2.
  4. You must use separate compilation for this project. Your main program must be called proj4.c All functions for this project must be found in crypto.c and your header file must be called crypto.h.
  5. Your header file must act as a user interface, meaning each function prototype must have a full function header comment above it. Function header comments are also required above the function definitions themselves.
  6. You must use top-down design. Your project will be graded for good design as in projects 2 and 3.

Assumptions

Your program may make the following assumption
  1. All filenames will be a maximum of 50 characters.
  2. As in project 3, graders will enter only one character and the newline for the menu choice.

The Translation Table File

The command line argument for your program is the name of the file that contains the translation table for the letter substitution. The file contains the 26 letters of the alphabet in scrambled order. Read the entire contents of this file into your program.

The first letter in the file should be substituted for the letter 'a'. The second letter in the file should be substituted for the letter 'b', the third letter for 'c' and so on. The last letter in the file is substituted for 'z'.

The letters in the file are lowercase. Use the same letters for UPPERCASE substitution as for lowercase.
I.e., if the first letter in the file is 'w', then substitute 'w' for 'a' and 'W' for 'A'.

Data Files

Several data files are available for you to use for testing. In Mr. Frey's public directory /afs/umbc.edu/users/d/e/dennis/pub/cs201/P4Data you will find the following files. You may copy them to your directory for testing.
  1. code1.dat and code2.dat that each contain a translation table as described in the section above
  2. song1.dat that contains the first verse of a song. This file was encrypted (and so must be decrypted) with code1.dat
  3. song2.dat that contains the first verse of the same song. This file was encrypted (and so must be decrypted) with code2.dat
  4. sayings1.dat that contains a few well-known sayings. This file was encrypted (and so must be decrypted) with code1.dat
  5. sayings2.dat that contains the same well-known sayings. This file was encrypted (and so must be decrypted) with code2.dat
  6. test.dat which contains a well known phrase that contains every letter of the alphabet. It is not encrypted.
You may use these files or create your own files for testing.

Sample Output

umbc9[1]% a.out code1.dat Print your greeting here Menu: E Encrypt D Decrypt T Print Translation Table Q Quit Please enter menu selection: e Please enter input file name (50 chars max): test.dat Please enter output file name (50 chars max): test.out Start Encryption Orginal Text: This message contains all letters of the alphabet: The quick brown fox jumped over the lazy dog. Encrypted Text: Qran gunnceu mihqcahn cff fuqquln it qru cfjrcouq: Qru ksamd oliwh tix bsgjup ivul qru fczy pie. Encryption complete 78 characters encoded 99 total characters processed Menu: E Encrypt D Decrypt T Print Translation Table Q Quit Please enter menu selection: d Please enter input file name (50 chars max): test.out Start Decryption Coded Text: Qran gunnceu mihqcahn cff fuqquln it qru cfjrcouq: Qru ksamd oliwh tix bsgjup ivul qru fczy pie. Decoded Text: This message contains all letters of the alphabet: The quick brown fox jumped over the lazy dog. Decryption complete 78 characters decoded 99 total characters processed Menu: E Encrypt D Decrypt T Print Translation Table Q Quit Please enter menu selection: t The translation table: c o m p u t e r a b d f g h i j k l n q s v w x y z Menu: E Encrypt D Decrypt T Print Translation Table Q Quit Please enter menu selection: T The translation table: c o m p u t e r a b d f g h i j k l n q s v w x y z Menu: E Encrypt D Decrypt T Print Translation Table Q Quit Please enter menu selection: M Your choice is invalid; please choose again Please enter menu selection: Q Processing Summary 2 files translated 156 characters translated 198 total characters processed Your thank you message goes here. umbc9[2]%

Although your output need not be identical to the above, all information (including the greeting) must be present.

Extra Credit

This project provides for 10 points of extra credit. The extra credit is earned by modifying your program to create the translation table rather than reading it from a file. Check out the extra credit description for details.

Submitting the Program

Since you must use separate compilation for this project, you will have several files that must be submitted for this project. The source file that contains main() MUST be called proj4.c, the file containing your functions MUST be called crypto.c, and the header file MUST be called crypto.h
To submit your project, type the following at the Unix prompt. Note that the project name starts with uppercase 'P'.

submit cs201 Proj4 proj4.c crypto.c crypto.h

Do NOT forget to submit your crypto.h file. Your program will NOT compile without it.

To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show all files that you submitted in a format similar to the Unix 'ls' command.

submitls cs201 Proj4


CSEE | 201 | 201 S'00 | lectures | news | help

Monday, 10-Apr-2000 11:41:38 EDT