
A common and simple form of cipher is a substitution cipher where each character in the plain text is substituted for another character in the cipher text. e.g. 'A' becomes 'D', 'B' becomes 'E', etc. ROT13 is an encryption program commonly found on UNIX systems which utilizes such a substitution cipher rotating each character by 13.
Task: You are to write a program in Java which implements a substitution cipher where every character and symbol in a plain text message is rotated by 1.
e.g:
plain text a, b, c, d, e, f, ...,
etc.
cipher text
b, c, d, e, f, g, ..., etc.
The program should be able to accept a plain text message either from the keyboard or file, encrypt it, and then write the output to either the screen or a file depending on the command line arguments given.
Several scenarios must be catered for:
|
|
|
| java Cipher | Displays main menu and only accepts keyboard I/O |
| java Cipher e | Enters Encrypt mode and only accepts keyboard I/O |
| java Cipher d | Enters Decrypt mode and only accepts keyboard I/O |
| java Cipher e infile | Enters Encrypt mode using infile as a source for plain text, prompts user for outfile |
| java Cipher e infile outfile | Enters Encrypt mode using infile as a source for plain text, writes cipher text to outfile |
| java Cipher d infile | Enters Decrypt mode using infile as a source for plain text, prompts user for outfile |
| java Cipher d infile outfile | Enters Decrypt mode using infile as a source for plain text, writes cipher text to outfile |
If no command line arguments are given the program will present the user with a main menu providing the following options:
*** Main Menu ***
e Encrypt mode
d Decrypt mode
x Exit
Enter choice:
| Enter choice: e
*Encrypt Mode* Enter message to encrypt: The fat cat sat on the mat. |
Enter choice: d
*Decrypt Mode* Enter message to decrypt: Uif gbu dbu tbu po uif nbu/ |
Enter choice: x
Exiting program..
|
| Encrypted message: Uif gbu dbu tbu po uif nbu/ | Decrypted message: The fat cat sat on the mat. |
Alternately encrypt or decrypt mode may be entered into directly at
the command line bypassing the main menu by providing the command line
arguments 'd' or 'e'. With all input being entered via keyboard.
When the operation is complete the main menu will be displayed.
| java Cipher e
*Encrypt Mode* Enter message to encrypt: |
java Cipher d
*Decrypt Mode* Enter message to decrypt: |
In addition the user may specify file input or output by providing file
names at the command line.
| java Cipher e infile.txt outfile.txt
*Encrypt Mode* Encryption Complete
Exiting program.. |
java Cipher d infile.txt outfile.txt
*Decrypt Mode* Decryption Complete
Exiting program.. |
If the outfile name is absent the program will prompt the user for a
name before encyrption/decryption commences.
| java Cipher e infile.txt
*Encrypt Mode* Please enter name of output file: |
java Cipher d infile.txt
*Decrypt Mode* Please enter name of output file: |
Once the desired operation has been performed the program terminates.
Due Date
Week 7
Submission Details
Email source code to your tutor
Marking Scheme
Execution
Program structure and design
Exception checking/handeling
Comments
Formatting