Im trying to encrypt a .txt file using the CaesarCipher method.
Below is what i have so far after roughly following an example in Horstmann's book.
I get errors when trying to compile "reader" and im pretty sure there is an error when trying to initialize encrypt scanner. Any help would be great.
PHP Code:
import java.util.Scanner;
import java.io.*;
public class CaesarCipher
{
public CaesarCipher(int aKey)
{
Key = 4;
}
public void encryptScanner(Scanner in, PrintWriter out)
throws exception IOException
{
boolean done = false;
while (!done)
{
int next = in.read();
if (next == -1) done = true;
else
{
char c = (char) next;
char b = encrypt(c);
out.write(c);
}
}
}
public char encrypt(char c)
{
return (char) (c + Key);
}
private int Key;
}
PHP Code:
import java.io.FileReader;
import java.util.Scanner;
import java.io.*;
public class reader
{
public static void main( String[] args)
throws IOException
{
File file = new File("poem.txt");
Scanner in = new Scanner(file);
PrintWriter out = new PrintWriter("encrypted.txt");
CaesarCipher cipher = new CaesarCipher(Key);
cipher.encryptScanner(Scanner, PrintWriter);
in.close();
out.close();
}
}