-3

I have made an encryption and decryption class and now i want to test it. The encrypter shold take som text and encrypt it into an .txt file. But it does not work.

public class Encryption extends FilterWriter{
private static int INKREMENT = 3;

protected Encryption(Writer arg0) {
    super(arg0);
}

public void write(String str, int off, int len) throws IOException{
    String result = str.substring(0,off);
    for(int i = off; i<len+off; i++){
        result += (char) ((int) str.charAt(i)+ INKREMENT);
    }
    result += str.substring(off+len);
    out.write(result);
}
public void write(int c) throws IOException{
        out.write(c + INKREMENT);


}
public void write(char[] cbuf, int off, int len) throws IOException{
    for(int i = off; i < len + off; i++){
        cbuf[i] = (char)((int) cbuf[i] + INKREMENT);
    }
    out.write(cbuf,off,len);
}

}

My test ? I dont know what to write to get a string encrypted and saved in the text.txt file

Writer out = new Encryption(new BufferedWriter(new FileWriter("text.txt")));
uthen
  • 447
  • 1
  • 5
  • 9

1 Answers1

0

See javax.crypto.CipherOutputStream. It's already done.

user207421
  • 305,947
  • 44
  • 307
  • 483