Assignment 5 -- File stuff
Encrypting and decrypting files
50 points

Due Wednesday, May 19th by 11:59:59pm

Design a program that allows the user to encrypt or decrypt a file. A menu should be repetitively displayed that allows the user to: (a) encrypt a file, (b) decrypt an encrypted file, or (c) quit. To encrypt a file you will shift any alphabetical character a specified number of spaces to the left or right as though the alphabet were circular (this is shown below and will be further explained in class). All other characters should be written 'as is.'


NORMAL ALPHABET:   A   B   C   D   E   F   G   H
--------------- - - - - - - - -
SHIFT RIGHT BY 2: Y Z A B C D E F
SHIFT LEFT BY 3: D E F G H I J K

This means you will need to ask the user the direction to shift (left or right) and the number of places to shift (should they choose to encrypt a file). The number of places a file can be shifted is anywhere from 0 to 2 billion. You may assume the input from the user will be in this range (the user will NOT enter a negative number). If the user chooses to encrypt, present them with a menu that finds out which direction to shift for encryption (left or right). When encrypting a file, before you write the encrypted data to an output file, you'll need to get the name of the file to encrypt and what to call the encrypted file from the user.  The first thing in the file you build that is encrypted is the direction of the shift ('left' or 'right' -- use these words), followed by a space, followed by the number of spaces shifted. This information will be used by the decrypt portion of this program. Finally, you can proceed to write the encrypted data to the file.

To decrypt a file, get the name of the file to decrypt from the user and the name the user wants to call the decrypted file. Use the direction and places found on the first line in the encrypted file to determine how to decrypt. You may assume the first line of the file will contain the direction of shift followed by the number of places shifted. You may also assume the file to decrypt exists. Be sure NOT to include the shift direction and number of spaces in the decrypted file!

NOTE: once a file has been encrypted or decrypted, be sure and close that file!

You will/may need a total of three (3) files for this project: the original input file, the file you created from encrypting, and the file created from decrypting. Depending on what the user chooses to do, you may not ever create an encrypted and decrypted file. Incidentally, the decrypted file should end up looking the same as the original file...

The only output to the monitor in this program is: (1) the menu requesting input to encrypt, decrypt, or quit (2) request for the name of an input file, name to call encrypted file, and the direction of shift and number of places if encrypt is chosen (3) request for name of the encrypted file and what to call the decrypted file if decrypt is chosen (4) error messages resulting from a file not opening.


Here is the 'official' input file will for you to test this program. You should use a file of your own to test your program first (probably one that's far simpler).


Name your class FileEncrypter.  


TO TURN IN:

  1. FileEncrypter.java
  2. The official input file
  3. Encrypted files of the official input file encrypted as follows: