public int processBlock(byte[] in, int inOff, byte[] out, int outOff)
      throws DataLengthException, IllegalStateException {
    cipher.processBlock(counter, 0, counterOut, 0);

    //
    // XOR the counterOut with the plaintext producing the cipher text
    //
    for (int i = 0; i < counterOut.length; i++) {
      out[outOff + i] = (byte) (counterOut[i] ^ in[inOff + i]);
    }

    int carry = 1;

    for (int i = counter.length - 1; i >= 0; i--) {
      int x = (counter[i] & 0xff) + carry;

      if (x > 0xff) {
        carry = 1;
      } else {
        carry = 0;
      }

      counter[i] = (byte) x;
    }

    return counter.length;
  }
  // Encrypt function, ECB mode
  private void E(byte[] key, byte[] s, int sOff, byte[] in, int inOff) {
    cipher.init(true, new KeyParameter(key));

    cipher.processBlock(in, inOff, s, sOff);
  }