public Object makeKey(byte[] kb, int blockSize) throws InvalidKeyException {
      // Not strictly true, but here to conform with the AES proposal.
      // This restriction can be removed if deemed necessary.
      if (kb.length != 16 && kb.length != 24 && kb.length != 32) {
         throw new InvalidKeyException("Key length is not 16, 24, or 32 bytes");
      }
      Key key = new Key();

      // Here w is our "pre-key".
      int[] w = new int[4 * (ROUNDS + 1)];
      int i, j;
      for (i = 0, j = 0; i < 8 && j < kb.length; i++) {
         w[i] = (kb[j++] & 0xff)       | (kb[j++] & 0xff) <<  8 |
                (kb[j++] & 0xff) << 16 | (kb[j++] & 0xff) << 24;
      }
      // Pad key if < 256 bits.
      if (i != 8) {
         w[i] = 1;
      }
      // Transform using w_i-8 ... w_i-1
      for (i = 8, j = 0; i < 16; i++) {
         int t = w[j] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ PHI ^ j++;
         w[i] = t << 11 | t >>> 21;
      }
      // Translate by 8.
      for (i = 0; i < 8; i++) {
         w[i] = w[i + 8];
      }
      // Transform the rest of the key.
      for ( ; i < w.length; i++) {
         int t = w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ PHI ^ i;
         w[i] = t << 11 | t >>> 21;
      }

      // After these s-boxes the pre-key (w, above) will become the
      // session key (key, below).
      sbox3(w[0], w[1], w[2], w[3]);
      key.k0 = x0; key.k1 = x1; key.k2 = x2; key.k3 = x3;
      sbox2(w[4], w[5], w[6], w[7]);
      key.k4 = x0; key.k5 = x1; key.k6 = x2; key.k7 = x3;
      sbox1(w[8], w[9], w[10], w[11]);
      key.k8 = x0; key.k9 = x1; key.k10 = x2; key.k11 = x3;
      sbox0(w[12], w[13], w[14], w[15]);
      key.k12 = x0; key.k13 = x1; key.k14 = x2; key.k15 = x3;
      sbox7(w[16], w[17], w[18], w[19]);
      key.k16 = x0; key.k17 = x1; key.k18 = x2; key.k19 = x3;
      sbox6(w[20], w[21], w[22], w[23]);
      key.k20 = x0; key.k21 = x1; key.k22 = x2; key.k23 = x3;
      sbox5(w[24], w[25], w[26], w[27]);
      key.k24 = x0; key.k25 = x1; key.k26 = x2; key.k27 = x3;
      sbox4(w[28], w[29], w[30], w[31]);
      key.k28 = x0; key.k29 = x1; key.k30 = x2; key.k31 = x3;
      sbox3(w[32], w[33], w[34], w[35]);
      key.k32 = x0; key.k33 = x1; key.k34 = x2; key.k35 = x3;
      sbox2(w[36], w[37], w[38], w[39]);
      key.k36 = x0; key.k37 = x1; key.k38 = x2; key.k39 = x3;
      sbox1(w[40], w[41], w[42], w[43]);
      key.k40 = x0; key.k41 = x1; key.k42 = x2; key.k43 = x3;
      sbox0(w[44], w[45], w[46], w[47]);
      key.k44 = x0; key.k45 = x1; key.k46 = x2; key.k47 = x3;
      sbox7(w[48], w[49], w[50], w[51]);
      key.k48 = x0; key.k49 = x1; key.k50 = x2; key.k51 = x3;
      sbox6(w[52], w[53], w[54], w[55]);
      key.k52 = x0; key.k53 = x1; key.k54 = x2; key.k55 = x3;
      sbox5(w[56], w[57], w[58], w[59]);
      key.k56 = x0; key.k57 = x1; key.k58 = x2; key.k59 = x3;
      sbox4(w[60], w[61], w[62], w[63]);
      key.k60 = x0; key.k61 = x1; key.k62 = x2; key.k63 = x3;
      sbox3(w[64], w[65], w[66], w[67]);
      key.k64 = x0; key.k65 = x1; key.k66 = x2; key.k67 = x3;
      sbox2(w[68], w[69], w[70], w[71]);
      key.k68 = x0; key.k69 = x1; key.k70 = x2; key.k71 = x3;
      sbox1(w[72], w[73], w[74], w[75]);
      key.k72 = x0; key.k73 = x1; key.k74 = x2; key.k75 = x3;
      sbox0(w[76], w[77], w[78], w[79]);
      key.k76 = x0; key.k77 = x1; key.k78 = x2; key.k79 = x3;
      sbox7(w[80], w[81], w[82], w[83]);
      key.k80 = x0; key.k81 = x1; key.k82 = x2; key.k83 = x3;
      sbox6(w[84], w[85], w[86], w[87]);
      key.k84 = x0; key.k85 = x1; key.k86 = x2; key.k87 = x3;
      sbox5(w[88], w[89], w[90], w[91]);
      key.k88 = x0; key.k89 = x1; key.k90 = x2; key.k91 = x3;
      sbox4(w[92], w[93], w[94], w[95]);
      key.k92 = x0; key.k93 = x1; key.k94 = x2; key.k95 = x3;
      sbox3(w[96], w[97], w[98], w[99]);
      key.k96 = x0; key.k97 = x1; key.k98 = x2; key.k99 = x3;
      sbox2(w[100], w[101], w[102], w[103]);
      key.k100 = x0; key.k101 = x1; key.k102 = x2; key.k103 = x3;
      sbox1(w[104], w[105], w[106], w[107]);
      key.k104 = x0; key.k105 = x1; key.k106 = x2; key.k107 = x3;
      sbox0(w[108], w[109], w[110], w[111]);
      key.k108 = x0; key.k109 = x1; key.k110 = x2; key.k111 = x3;
      sbox7(w[112], w[113], w[114], w[115]);
      key.k112 = x0; key.k113 = x1; key.k114 = x2; key.k115 = x3;
      sbox6(w[116], w[117], w[118], w[119]);
      key.k116 = x0; key.k117 = x1; key.k118 = x2; key.k119 = x3;
      sbox5(w[120], w[121], w[122], w[123]);
      key.k120 = x0; key.k121 = x1; key.k122 = x2; key.k123 = x3;
      sbox4(w[124], w[125], w[126], w[127]);
      key.k124 = x0; key.k125 = x1; key.k126 = x2; key.k127 = x3;
      sbox3(w[128], w[129], w[130], w[131]);
      key.k128 = x0; key.k129 = x1; key.k130 = x2; key.k131 = x3;

      return key;
   }