public class TrickCipher implements Cipher { private int max; private TinyCipher tc; public TrickCipher(int max, byte[] key) { if (max <= 0) throw new IllegalArgumentException("max must be positive: " + max); this.max = max; int numBits = BitTools.lb(max); tc = new TinyCipher(numBits, key); } public int encrypt(int x) { if (x >= max) throw new IllegalArgumentException("x must be less than max: " + x); do { x = tc.encrypt(x); } while(x >= max); return x; } public int decrypt(int x) { if (x >= max) throw new IllegalArgumentException("x must be less than max: " + x); do { x = tc.decrypt(x); } while(x >= max); return x; } }