CPSC 150B Fall 2000
Program 3a: Encryption

Write a C++ program that encrypts a text file using a version of the Caesar cipher as described below.

Input

Your program should prompt the user for the name of the file to be encrypted, the name of the file where the encrypted text should be written, and the (integer) value of the shift to be used in the encryption.

Output

Your program should write the encrypted text to the specified file and print a message indicating that it has done so.

The Encryption Process

Your program should encrypt the file by shifting each letter the amount indicated by the user. For example, if the user enters 3 for the shift, A in the plaintext should become D in the ciphertext, and Y in the plaintext should become B in the ciphertext; if the user enters -3 for the shift, A in the plaintext should become X in the ciphertext. If the user enters a shift with an absolute value greater than 26 (or less than -26), the effect is that of the value mod 26. That is, if the shift is 29 (or 55 or 81 or...) then A should become D -- just as if the shift were 3.

All uppercase letters in the plaintext should be encrypted in the ciphertext. All other characters (spaces, punctuation, lower case letters, etc.) should be left unencrypted. Thus the ciphertext will have the same structure as the regular text; e.g., plaintext "HI THERE!" would become ciphertext "KL WKHUH!".

Your program should "work" if the input file is empty -- it should simply create an empty encrypted file.

Program Structure

Imagine the Caesar cipher as a machine that can be initialized with a shift value but can also have that shift value changed. This machine should be able to encrypt any file you give it, that is, one of its functions should be to take the name of a file to be encrypted and the name of the file for the encrypted text to go in and perform the encryption.

Thinking of the cipher as a machine, it makes sense to use a class with the appropriate public and private member functions and member data to model it. Define this class, then create an instance of it to actually do your encryption. Note that this means that you will need three files all together for your project: a .h file giving the declaration for the cipher class; a .cc file giving the function definitions for that class; and a main (.cc) file that creates an instance of your cipher class, gets the shift and filenames from the user, and calls the appropriate member function(s) to do the encryption.

Some Useful Information

A couple of things you might find useful in this program:

Style and Documentation

As always, your program should be clean (no clutter!) and well documented. Provide a header for each file containing your name, the date, the path where the file lives and a description of what it contains, as well as a header for each function describing what it takes, what it returns, any I/O it performs, and anything interesting about the method it uses.