Create an interface that allows a user to encrypt/decrypt text files using (minimally) 12 bit single-error-correcting Hamming codes. 12-bit error correcting codes allow an 8bit char to be sent. To send two chars – or a 16 bit Unicode value) you would need a 21-bit Hamming solution.
· Since Java applets can’t read from a file, this will be a Frame-based application. A frame is a window.
· Provide a GUI with a JTextArea in the (borderlayout) center.
· For output, read the user's file and convert chars into 8 bit ASCII code. Put into 12 bit "array" with correction/parity bits. Write these "arrays" of binary values to an output file and also display them in the textarea.
· For input, read your "arrays" of 12 bit Hamming codes from an input file. Check/correct single bit errors. Write the characters to an output file and the also display text area.
Extra credit: Do
Hamming 21 bit (or some other size) instead
As always, you should
work on the individual pieces SEPARATELY, in case you can’t complete some
parts. Here’s a work schedule:
· Convert chars into a binary representation of their ASCII codes
· Pack these into the correct positions of a 12-bit array
· Fill the other bit positions with the Hamming parity bits
There are lots of ways to do everything in java. Here’s
a program which reads a file using a scanner and outputs the contents as
strings to another (.txt) file:
import java.util.*;
import java.io.*;
public class FileCopy{
public static void main (String args[]){
String first;
Scanner input;
String FileName1=args[0];
String FileName2=args[1];
try{
BufferedWriter bw=new BufferedWriter(new FileWriter(FileName2));
FileInputStream fis=new FileInputStream(FileName1);
input=new Scanner(fis);
while(input.hasNext()){
first=input.nextLine();
bw.write (first);
bw.newLine();
System.out.println(first);//echo to screen as well
}
fis.close();
dos.close();
}//try
catch(IOException e){}
}}
Here’s the run and
contents of the output.txt file
C:\PROGRA~1\JAVA\JDK15~1.0_0\BIN>java FileCopy input.txt output.txt
here is a
sample
input file
With several lines
C:\PROGRA~1\JAVA\JDK15~1.0_0\BIN>type output.txt
here is a
sample
input file
With several lines