Package freenet.support.math

Examples of freenet.support.math.MersenneTwister.nextInt()


  }
 
  public void testEncodeDecodeRandomLength() throws CHKEncodeException, CHKVerifyException, CHKDecodeException, UnsupportedEncodingException, InvalidCompressionCodecException, IOException
    MersenneTwister random = new MersenneTwister(42);
    for(int i=0;i<10;i++) {
      byte[] buf = new byte[random.nextInt(CHKBlock.DATA_LENGTH+1)];
      random.nextBytes(buf);
      checkBlock(buf, false);
      checkBlock(buf, true);
    }
  }
View Full Code Here


      MersenneTwister random = new MersenneTwister(seed);
      int ptr = 0;
      System.arraycopy(plaintext, 0, output, 0, plaintext.length);
      while (ptr < plaintext.length) {
        int max = plaintext.length - ptr;
        int count = (max == 1) ? 1 : (random.nextInt(max - 1) + 1);
        /*ctr.blockEncipher(plaintext, ptr, count, output, ptr);*/
        ctr.blockEncipher(output, ptr, count);
        ptr += count;
      }
      assertTrue(Arrays.equals(output, ciphertext));
View Full Code Here

      assertTrue(Arrays.equals(output, ciphertext));
      ctr.reset(iv);
      ptr = 0;
      while (ptr < plaintext.length) {
        int max = plaintext.length - ptr;
        int count = (max == 1) ? 1 : (random.nextInt(max - 1) + 1);
        /*ctr.blockDecipher(output, ptr, count, output, ptr);*/
        ctr.blockDecipher(output, ptr, count);
        ptr += count;
      }
      assertTrue(Arrays.equals(output, plaintext));
View Full Code Here

      MersenneTwister random = new MersenneTwister(mt.nextLong());
      int ptr = 0;
      System.arraycopy(plaintext, 0, output, 0, plaintext.length);
      while (ptr < plaintext.length) {
        int max = plaintext.length - ptr;
        int count = (max == 1) ? 1 : (random.nextInt(max - 1) + 1);
        //ctr.blockEncipher(plaintext, ptr, count, output, ptr);
        ctr.blockEncipher(output, ptr, count);
        ptr += count;
      }
      assertTrue(Arrays.equals(output, ciphertext));
View Full Code Here

      // ... and decrypt again, in random pieces.
      ptr = 0;
      ctr.reset(iv);
      while (ptr < plaintext.length) {
        int max = plaintext.length - ptr;
        int count = (max == 1) ? 1 : (random.nextInt(max - 1) + 1);
        //ctr.blockDecipher(output, ptr, count, output, ptr);
        ctr.blockDecipher(output, ptr, count);
        ptr += count;
      }
      assertTrue(Arrays.equals(output, plaintext));
View Full Code Here

        // For CTR it should be able to return immediately each time.
        // ... Actually, no. BouncyCastle's CTR breaks this assumption.
        // You must handle when update() produce less than was in input.
        while (inputPtr < plaintext.length) {
          int max = plaintext.length - inputPtr;
          int count = (max == 1) ? 1 : (random.nextInt(max - 1) + 1);
          int moved = c.update(plaintext, inputPtr, count, output,
              outputPtr);
          outputPtr += moved;
          inputPtr += count;
        }
View Full Code Here

      byte[] output = new byte[plaintext.length];
      MersenneTwister random = new MersenneTwister(seed);
      int ptr = 0;
      while (ptr < plaintext.length) {
        int max = plaintext.length - ptr;
        int count = (max == 1) ? 1 : (random.nextInt(max - 1) + 1);
        ctr.processBytes(plaintext, ptr, count, output, ptr);
        ptr += count;
      }
      assertTrue(Arrays.equals(output, ciphertext));
    }
View Full Code Here

      byte[] output = new byte[plaintext.length];
      MersenneTwister random = new MersenneTwister(mt.nextLong());
      int ptr = 0;
      while (ptr < plaintext.length) {
        int max = plaintext.length - ptr;
        int count = (max == 1) ? 1 : (random.nextInt(max - 1) + 1);
        ctr.processBytes(plaintext, ptr, count, output, ptr);
        ptr += count;
      }
      assertTrue(Arrays.equals(output, ciphertext));
     
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.