import java.io.FileInputStream; import java.io.FileOutputStream; public class DumbCrypt { private int generator; public void setKey(int key){ generator = key; } public byte[] crypt(byte[] input){ byte[] output = new byte[input.length]; // generate some pseudo-random bytes for(int i = 0; i < input.length; i++){ generator *= 314159; generator += 2718; output[i] = (byte) generator; } // then exclusive-or each with an input byte for(int i = 0; i < input.length; i++){ output[i] ^= input[i]; } return output; } public static void main(String args[]) throws Exception { if(args.length < 2 || args.length > 3){ System.err.println("usage: java DumbCrypt inFile outFile [key]"); System.exit(1); } else if(args.length < 3){ System.err.println("Key recovery feature not yet written.\n"); System.exit(1); } else { DumbCrypt crypter = new DumbCrypt(); crypter.setKey(Integer.parseInt(args[2])); FileInputStream inStream = new FileInputStream(args[0]); byte[] input = new byte[inStream.available()]; inStream.read(input); FileOutputStream outStream = new FileOutputStream(args[1]); outStream.write(crypter.crypt(input)); } } }