Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

File encryption is the science of writing the contents of a file in a secret cod

ID: 3706047 • Letter: F

Question

File encryption is the science of writing the contents of a file in a secret code. Your encryption program should work like a filter, reading the contents of one file modifying the data into a code, and then writing the coded contents out to a second file.

There are very complex encryption techniques, but for ours, will use a simple one from the shift category. We will take each character and shift it one place in the Unicode sequence. So ‘a’ becomes ‘b’, ‘b’ becomes ‘c’, etc. What about ‘z’? You could make it ‘a’ or just the next Unicode character, which is the choice we will take.

NOTE: you must be writing and reading a text file, not a serializable one, and you must have a FileDialog box where the user can choose the file to utilize.

Write a program that has the following menu choices:

1. Read in a file

2. Print the file to the console (obviously – this is for debugging only)

3. Encrypt the file and write it to the console

4. Write out the encrypted file to a text file

5. Clear the data in memory

6. Read in an encrypted file

7. Decrypt the file

8. Write out the decrypted file to the console

9. End

Explanation / Answer

public static void FileEncrypt()

{

String fileName = "temp1.txt";

String line = null;

String bar="";

try

{

FileReader fileReader = new FileReader(fileName);

BufferedReader bufferedReader = new BufferedReader(fileReader);

while((line = bufferedReader.readLine()) != null)

{

for (char c : line.toCharArray())

{   

bar += Character.toString((char) (((c - 'a' + 1) % 26) + 'a'));

}

System.out.println(bar);

}   

bufferedReader.close();

}

catch(FileNotFoundException ex)

{

System.out.println("Unable to open file '" +fileName + "'");   

}

catch(IOException ex)

{

System.out.println("Error reading file '"+ fileName + "'");   

  

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote