import java.io.FileReader; import java.io.PrintStream; /** * Class for encoding entire files. * @author Dave Reed * @version 3/22/08 */ public class Encrypt { /** * Constructs an Encrypt object. */ public Encrypt() { // currently, does nothing } /** * Encodes an entire file using a Cipher object. * @param sourceFile the input file to be encoded * @param codedFile the encoded output file */ public void encodeFile(String sourceFile, String codedFile) { Cipher coder = new Cipher(); try { FileReader infile = new FileReader(sourceFile); PrintStream outfile = new PrintStream(codedFile); while (infile.ready()) { char ch = (char)infile.read(); outfile.print( coder.encode(ch) ); } infile.close(); outfile.close(); } catch (java.io.IOException e) { System.out.println("FILE NOT FOUND"); } } /** * Decodes an entire file using a Cipher object. * @param codedFile the input file to be decoded * @param sourceFile the decoded output file */ public void decodeFile(String codedFile, String sourceFile) { Cipher coder = new Cipher(); try { FileReader infile = new FileReader(codedFile); PrintStream outfile = new PrintStream(sourceFile); while (infile.ready()) { char ch = (char)infile.read(); outfile.print( coder.decode(ch) ); } infile.close(); outfile.close(); } catch (java.io.IOException e) { System.out.println("FILE NOT FOUND"); } } }