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: 3594614 • 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. The second file will be a version of the first file, but written in a secret code. Although there are complex encryption techniques, you should come up with a simple one of your own. For example, you could read the first file one character at a time, and add 10 to the character code of each character before it is written to the second file.
The Crypto.java encrypts the data. FileEncryptionFilter.java demonstrates a solution using Crypto class to make an encrypted copy of the file "MyLetters.txt". The encrypted copy is stored in "Encrypted.txt".

Crypto.java is incomplete. Please complete Crypto.java to fulfill the encryption function. You need to use Exception Handling and proper File I/O operation in your Crypto.java.

This is what I have for Crypto.java - my professor said everything looked good except I need to have something in my while loop...I just have no idea what needs to go there. Can anyone help me?

---------------------------------------------------------------

Crypto.java

package crypto.java;

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import javax.crypto.Cipher;

import javax.crypto.KeyGenerator;

import javax.crypto.SecretKey;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

*

* @author Kadie

*/

public class Crypto {

/**

* @param args the command line arguments

*/

public static void encryptFile(String existing, String encrypted)

throws IOException

{

boolean eof = false; // End of file flag

  

// Open the files.

FileInputStream inStream = new FileInputStream(existing);

DataInputStream inFile = new DataInputStream(inStream);

  

FileOutputStream outStream = new FileOutputStream(encrypted);

DataOutputStream outFile = new DataOutputStream(outStream);

  

// Process the file. TIP: use readByte:

//byte input = inFile.readByte();

while (!eof)

{

}

  

//close the files

}

}

-------------------------------------------------------

FileEncryptionFilter.java

import crypto.java.Crypto;
import java.io.*;

/**
This program demonstrates a solution to the
File Encryption Filter programming challenge.

This program makes an encrypted copy of the file
"MyLetters.txt". The encrypted copy is stored
in "Encrypted.txt".
*/

public class FileEncryptionFilter
{
public static void main(String[] args)
{
System.out.println("Encrypting the contents of the file");
System.out.println("MyLetters.txt. The encrypted file will");
System.out.println("be stored as Encrypted.txt");

try
{
Crypto.encryptFile("MyLetters.txt", "Encrypted.txt");
System.out.println("Done. Use Notepad to inspect the encrypted file.");
}
catch (IOException e)
{
System.out.println("Error - " + e.getMessage());
}
}
}

Explanation / Answer

Inside the while loop you must should implement the logic for encryption and here is the complete code.

package crypto.java;

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import javax.crypto.Cipher;

import javax.crypto.KeyGenerator;

import javax.crypto.SecretKey;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

*

* @author Kadie

*/

public class Crypto {

/**

* @param args the command line arguments

*/

public static void encryptFile(String existing, String encrypted)

throws IOException

{

boolean eof = false; // End of file flag

  

// Open the files.

FileInputStream inStream = new FileInputStream(existing);

DataInputStream inFile = new DataInputStream(inStream);

  

FileOutputStream outStream = new FileOutputStream(encrypted);

DataOutputStream outFile = new DataOutputStream(outStream);

  

// Process the file. TIP: use readByte:

//byte

while (!eof)

{

input = inFile.readByte();

outFile.write(input +1);

}

  

//close the files

}

}

-------------------------------------------------------

FileEncryptionFilter.java

import crypto.java.Crypto;
import java.io.*;

/**
This program demonstrates a solution to the
File Encryption Filter programming challenge.

This program makes an encrypted copy of the file
"MyLetters.txt". The encrypted copy is stored
in "Encrypted.txt".
*/

public class FileEncryptionFilter
{
public static void main(String[] args)
{
System.out.println("Encrypting the contents of the file");
System.out.println("MyLetters.txt. The encrypted file will");
System.out.println("be stored as Encrypted.txt");

try
{
Crypto.encryptFile("MyLetters.txt", "Encrypted.txt");
System.out.println("Done. Use Notepad to inspect the encrypted file.");
}
catch (IOException e)
{
System.out.println("Error - " + e.getMessage());
}
}
}

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