1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
import java.io.*;
public class Encryptor
{
public Encryptor(int aKey)
{
key = aKey;
}
public void encryptFile(String inputFileName, String outputFileName) throws IOException
{
InputStream in = null;
OutputStream out = null;
try
{
in = new FileInputStream(inputFileName);
out = new FileOutputStream(outputFileName);
encryptStream(in,out);
}
finally
{
if(in != null)
in.close();
if(out != null)
out.close();
}
}
public void encryptStream(InputStream in, OutputStream out) throws IOException
{
boolean done = false;
while(!done)
{
int next = in.read();
if(next == -1)
done = true;
else
{
byte b = (byte)next;
byte c = encrypt(b);
out.write(c);
}
}
}
public byte encrypt(byte b)
{
return (byte)(b + key);
}
private int key;
} |
Partager