Need help please on this java Cryptography class Module 8.3 | Challenge The Cryp
ID: 3728302 • Letter: N
Question
Need help please on this java Cryptography class
Module 8.3 | Challenge The Cryptography Class Overview In this two-part challenge, you will create a Cryptography class with a public static encodeFile method and a public static decodeFile method. These methods encode and decode the contents of a file, respectively. Each method has an input file and an output file as parameters. Two testing programsl also be created For an overview on cryptography, watch this video presentation in Specifications Part 1 MyMessage.txt Create a text file named MyMessage.txt and enter these letters: abcdefg Note: The encrypted letters will be the letters: klmnopq MyMessage.txt will be encrypted by method encodeFile producing a secret code that will be stored in an output file EncryptedMessage.txt. Save MyMessage.txt in the same folder as the folder that will contain your Cryptography class and the test harness file Cryptography.java Create the skeleton of a class called Cryptography Create a public static methodencodeFile Add the throws clause to the method header for the IOException type FileInputstream and DataInputStream classes (java.io package) will be used to read from the input file (MyMessage.txt) A boolean variable endofFile should be declared and initialized to false Declare and create new FileInputStream, DataInputStream, FileOutputSteream, and DataOutputstream objects. Open the files. Process the files using the readByte and writeByte methods. Here is an algorithm: while not end of file: try read the next byte from the input file add 10 (which produces the new encoded character) write the byte to the output file catch using EOFException set the endoEFile filag to true Close the files.Explanation / Answer
Answer should be something like that Obviously you have to add the particular error message and need to add some proper formatting.
public class Cryptography {
public static void encodeFile(String args[]) throws IOException{
FileInputStream in = null;
FileOutputStream out = null;
DataInputStream datain=null;
DataOutputStream dataout=null;
datain = new DataInputStream(new FileInputStream("MyMessage.txt"));
dataout = new DataOutputStream(new FileOutputStream("EncryptedMessage.txt"));
byte ch;
try{
while (true) { // exception deals catches EOF
ch = datain.readByte();
ch=ch+10;
dataout.writeUTF(ch);
}
catch(){}
finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
public static void encodeFile(String args[]) throws IOException{
FileInputStream in = null;
FileOutputStream out = null;
DataInputStream datain=null;
DataOutputStream dataout=null;
datain = new DataInputStream(new FileInputStream("EncryptedMessage.txt"));
dataout = new DataOutputStream(new FileOutputStream("RecoveredMessage.txt"));
byte ch;
try{
while (true) { // exception deals catches EOF
ch = datain.readByte();
ch=ch-10;
dataout.writeUTF(ch);
}
catch(){}
finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.