Question: Chapter 11. PC # 7 & 8. File Encryption and Decryption Filters (page 758) The goal of this program is to implement the second phase

Chapter 11. PC # 7 & 8. File Encryption and Decryption Filters (page 758)

The goal of this program is to implement the second phase of the Caesar cipher project. For your homework choose a prime number between 5 and 255 (Id recommend: 13 which will turn your program into a variant of ROT13 cipher) for shifting the code of all symbols. The idea of this phase is that the file is always in an encrypted state, but the user is able to read and write regular text from and into it. The encryption/decryption will need to use circular addition method (using modulo operator) to wrap around, always generating codes within range of 0 to 255. Youll need to handle all exceptions gracefully.

Your project will contain the following classes:

In Java Language

class CaesarInputStream, which contains:

private FileInputStream object for reading from an encrypted file

public CaesarInputStream(String filename) - constructor that accepts the file name as a string

public char read() reads one character from the file

public String readString(int count) reads count characters form the file

public String readLine() reads one line from the file (up to the next encrypted new line character)

public void close() - closes the input stream

class CaesarOutputStream, which contains:

private FileOutputStream object for writing to an encrypted file

public CaesarOutputStream(String filename) constructor that accepts the file name as a string

public void write(char c) writes one character to the file

public void writeString(String str) writes a string to the file

public void writeLine(String str) writes a string to the file and adds a new line character (encrypted)

public void close() - closes the output stream

class Main, which contains:

public static void main(String[] args)

You can create additional methods as you see them fit, however they should be private. Only the above public methods are allowed. Your program will start by displaying a menu and prompting the user to select either to read from an encrypted file (option 1) or write to an encrypted file (option 2). If reading is specified by the user, your program will read the input file (specified by the user), decrypt it using the above method and display it on the screen. After that the program should return to the main menu. If writing is specified, your program will continuously ask the user to input string lines and write them to the output file until the user stops the entry process by typing EOF, at which point you will need to close the file and return back to the main menu.

2ENTER test.datENTER This is line 1.ENTER This is line 2.ENTER This is line 3.ENTER EOFENTER 1ENTER test.datENTER 3ENTER
1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): Please enter the file name or type QUIT to exit: Enter text to write to an encrypted file. At the end of the text type EOF on a separate line to stop: 1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): Please enter the file name or type QUIT to exit: This is line 1. This is line 2. This is line 3. 1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): 
2ENTER aaa\bbb/ccc:dddENTER quitENTER 3ENTER
1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): Please enter the file name or type QUIT to exit: Invalid file name. Please enter the file name again or type QUIT to exit: 1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): 
1ENTER test.datENTER quitENTER 3ENTER
1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): Please enter the file name or type QUIT to exit: File: test.dat does not exist. Please enter the file name again or type QUIT to exit: 1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): 
2ENTER test.datENTER ENTER EOFENTER 1ENTER test.datENTER 3ENTER

1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): Please enter the file name or type QUIT to exit: Enter text to write to an encrypted file. At the end of the text type EOF on a separate line to stop: 1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3): Please enter the file name or type QUIT to exit: 1. Read from an encrypted file 2. Write to an encrypted file 3. Quit the program Enter your choice (1, 2, or 3):

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!