Example #1
0
  @Override
  public void setup() {

    /** makes only once a new Skipjack. */
    if (algo == null) {
      algo = new Skipjack();
      if (publicKey == null) {
        java.util.Random rnd = new java.util.Random();
        rnd.nextBytes(publicKey);
      }
      algo.setupKey(publicKey);
    } else {
      algo.setupKey(publicKey);
    }
  }
Example #2
0
  @Override
  public byte readByte() {
    if (!isOpen()) {
      return -1;
    }

    if (filename == null && count > maxCount) {
      open = false;
      return -1;
    }

    if (outAlgoBufferIx == outAlgoBuffer.length) {
      algo.encrypt_block(inputAlgoBuffer, outAlgoBuffer);
      for (outAlgoBufferIx = 0; outAlgoBufferIx < inputAlgoBuffer.length; outAlgoBufferIx++) {
        inputAlgoBuffer[outAlgoBufferIx] = outAlgoBuffer[outAlgoBufferIx];
      }
      outAlgoBufferIx = 0;
    }

    byte prng = outAlgoBuffer[outAlgoBufferIx++];

    if (filename == null) {
      count++;
      return prng;
    }

    /*
     * we have a real filename to encrypt
     */
    byte data = super.readByte();
    return (byte) (prng ^ data);
  }