// Cipher.java -*- Java -*- // The Ciphering object // // Copyright(C) 1998 Robert Sexton // You can do anything you want with this, except pretend you // wrote it. // // Written : Robert Sexton University of Cincinnati // By // // Written : John Franco // For Special Topics: Java Programming // 15-625-595-001, Fall 1998 // RCS : // // $Source: /home/franco/CVS/html/Users/Franco/Project/Cipher.java,v $ // $Revision: 1.1.1.1 $ // $Date: 2008/04/03 01:33:07 $ // // $Log: Cipher.java,v $ // Revision 1.1.1.1 2008/04/03 01:33:07 franco // // // Revision 0.3 1998/12/02 06:51:33 bkuhn // -- added a bounds check // // Revision 0.2 1998/11/30 18:59:05 bkuhn // -- latest changes from Robert // // Revision 1.2 1998/11/30 18:48:11 robert // Added Guard Bytes. // // Revision 1.1 1998/11/30 13:53:59 robert // Initial revision // // Revision 0.1 1998/11/30 03:27:12 bkuhn // # initial version // import java.io.*; import java.util.Date; import java.math.BigInteger; import java.security.*; /* * class Cipher * Here's where the symmetrical encryption happens. * instantiate one of these, passing in a secret key (A BigInteger) * * This is an implementation of Phil Karn's algorithm, as described by * Schneier. Text is padded to the nearest 40 bytes. * Bigger padding sizes would result in less infomation leakage. * This algoritm is vulnerable to chosen plaintext attacks under some * specific circumstances, but on the whole its pretty secure * */ class Cipher { final int RADIX=32; final int PADSIZE=40; /* Plaintext buffer */ private byte key[]; private byte key_left[]; private byte key_right[]; static SecureRandom sr = null; /* This is expensive. We only need one */ MessageDigest md = null; Cipher(BigInteger bi) { if (sr == null) sr = new SecureRandom(); key = bi.toByteArray(); // System.out.println("C: key " + new BigInteger(key).toString(RADIX)); /* Digest encryption needs keys split into two halves */ key_left = new byte[key.length/2]; key_right = new byte[key.length/2]; /* I anxiously await a more elegant solution to the following */ for (int i = 0;i