TestPRG.java 767 B

12345678910111213141516171819202122232425262728293031
  1. package crypto;
  2. import java.math.BigInteger;
  3. public class TestPRG {
  4. public static void main(String[] args) {
  5. // PRG.generateKey(Crypto.sr);
  6. int n = 10;
  7. int outBits = 1000;
  8. int outBytes = (outBits + 7) / 8;
  9. byte[][] input = new byte[n][16];
  10. byte[][] output = new byte[n][];
  11. PRG G = new PRG(outBits);
  12. for (int i = 0; i < n; i++) {
  13. Crypto.sr.nextBytes(input[i]);
  14. output[i] = G.compute(input[i]);
  15. System.out.println(new BigInteger(1, output[i]).toString(16));
  16. }
  17. for (int i = 0; i < n; i++) {
  18. byte[] tmp = G.compute(input[i]);
  19. System.out.println(
  20. "deterministic:\t" + (new BigInteger(1, tmp).compareTo(new BigInteger(1, output[i])) == 0));
  21. System.out.println("right length:\t" + (output[i].length == outBytes));
  22. }
  23. }
  24. }