private static void set3(IBlockCipher cipher, int keySize) throws InvalidKeyException {
   String s;
   int kl = keySize / 8;
   int bl = cipher.defaultBlockSize();
   byte[] k = new byte[kl];
   byte[] p = new byte[bl];
   byte[] c = new byte[bl];
   byte[] d = new byte[bl];
   int j;
   System.out.println("Test vectors -- set 3");
   System.out.println("=====================");
   System.out.println();
   cipher.reset();
   HashMap map = new HashMap();
   for (int i = 0; i < 256; i++) {
     s = "   " + String.valueOf(i);
     s = s.substring(s.length() - 3);
     System.out.println("Set 3, vector#" + s + ":");
     for (j = 0; j < bl; j++) {
       k[j] = (byte) i;
       p[j] = (byte) i;
     }
     for (; j < kl; j++) {
       k[j] = (byte) i;
     }
     map.put(IBlockCipher.KEY_MATERIAL, k);
     cipher.init(map);
     System.out.println("                      key=" + Util.toString(k));
     System.out.println("                    plain=" + Util.toString(p));
     cipher.encryptBlock(p, 0, c, 0);
     System.out.println("                   cipher=" + Util.toString(c));
     cipher.decryptBlock(c, 0, d, 0);
     System.out.println("                decrypted=" + Util.toString(d));
     if (!Arrays.equals(p, d)) {
       throw new RuntimeException("Symmetric operation failure...");
     }
     for (j = 1; j < 100; j++) {
       cipher.encryptBlock(c, 0, c, 0);
     }
     System.out.println("       Iterated 100 times=" + Util.toString(c));
     for (j = 100; j < 1000; j++) {
       cipher.encryptBlock(c, 0, c, 0);
     }
     System.out.println("      Iterated 1000 times=" + Util.toString(c));
     System.out.println();
     cipher.reset();
   }
 }
  private static void set4(IBlockCipher cipher, int keySize) throws InvalidKeyException {
    // this is torture for low-speed CPUs. only execute if global env var
    // TORTURE is set!
    String dummy = System.getProperty("TORTURE");
    if (dummy == null) {
      return;
    }

    int kl = keySize / 8;
    int bl = cipher.defaultBlockSize();
    byte[] k = new byte[kl];
    byte[] p = new byte[bl];
    int j, t, x;
    System.out.println("Test vectors -- set 4");
    System.out.println("=====================");
    System.out.println();
    HashMap map = new HashMap();
    for (int i = 0; i < 4; i++) {
      System.out.println("Set 4, vector#  " + String.valueOf(i) + ":");
      for (j = 0; j < bl; j++) {
        k[j] = (byte) i;
        p[j] = (byte) i;
      }
      for (; j < kl; j++) {
        k[j] = (byte) i;
      }
      System.out.println("                      key=" + Util.toString(k));
      System.out.println("                    plain=" + Util.toString(p));
      x = i;
      for (j = 0; j < 100000000; j++) {
        for (t = 0; t < kl; t++) {
          k[t] = (byte) x;
        }
        map.put(IBlockCipher.KEY_MATERIAL, k);
        cipher.init(map);
        cipher.encryptBlock(p, 0, p, 0);
        cipher.reset();
        x = p[bl - 1] & 0xFF;
      }
      System.out.println("      Iterated 10^8 times=" + Util.toString(p));
      System.out.println();
    }
  }