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

Project: File Encryption Problem Description: Suppose an encrypted file was crea

ID: 3543892 • Letter: P

Question

Project: File Encryption

Problem Description:

Suppose an encrypted file was created by adding 5 to every byte in the file. Write a program to decode the encrypted file. Your program should prompt the user to enter an input file name and an output file name and should save the unencrypted version of the input file to the output file.

What should you do?

1. Run the following program to create an encrypted file.

(Delete this program when you print out this project to save paper.)

import java.util.Scanner;

import java.io.*;

public class Exercise19_14 {

  public static void main(String[] args) throws Exception {

    Scanner input = new Scanner(System.in);

    

    System.out.print("Enter a file to encrypt: ");

    BufferedInputStream in = new BufferedInputStream(

      new FileInputStream(new File(input.next())));

    System.out.print("Enter the output file: ");

    BufferedOutputStream output = new BufferedOutputStream(

      new FileOutputStream(new File(input.next())));

    int value;

    while ((value = in.read()) != -1) {

      output.write(value + 5);

    }

    

    input.close();

    output.close();

  }

}

2. Write a program to decrypt the file. Name your program Exercise19_15.

Submit the following items:

1. Compile and Submit to Zeus (you must submit the program regardless whether it complete or incomplete, correct or incorrect)

2. Fill in self-evaluation:  

Explanation / Answer

import java.util.Scanner;

import java.io.*;

public class Exercise19_14 {

public static void main(String[] args) throws Exception {

Scanner input = new Scanner(System.in);

System.out.print("Enter a file to decrypt: ");

BufferedInputStream in = new BufferedInputStream(

new FileInputStream(new File(input.next())));

System.out.print("Enter the output file: ");

BufferedOutputStream output = new BufferedOutputStream(

new FileOutputStream(new File(input.next())));

int value;

while ((value = in.read()) != -1) {

output.write(value - 5);

}

input.close();

output.close();

}

}