MiscTests.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package misc;
  2. import java.math.BigInteger;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import crypto.Crypto;
  7. import oram.Forest;
  8. import oram.Metadata;
  9. import oram.Tuple;
  10. import util.StopWatch;
  11. import util.Util;
  12. public class MiscTests {
  13. public static void main(String[] args) {
  14. /*
  15. * System.out.println("HelloWorld!");
  16. *
  17. * byte[] tmp = new byte[3]; BigInteger bi = new BigInteger(1, tmp);
  18. * System.out.println(bi.toByteArray().length);
  19. *
  20. * // System.out.println(tmp[3]);
  21. *
  22. * // System.out.println(Arrays.copyOfRange(tmp, 2, 1).length);
  23. *
  24. * byte[] a = new byte[] { 0 }; byte[] b = a.clone(); a[0] = 1;
  25. * System.out.println(a[0] + " " + b[0]); // throw new
  26. * ArrayIndexOutOfBoundsException("" + 11);
  27. *
  28. * System.out.println((new long[3])[0]);
  29. *
  30. * byte[] negInt = Util.intToBytes(-3); System.out.println(new
  31. * BigInteger(negInt).intValue());
  32. *
  33. * byte aa = 1; aa ^= 1; System.out.println(aa);
  34. */
  35. /*
  36. * Metadata md = new Metadata(); Forest forest =
  37. * Forest.readFromFile(md.getDefaultForestFileName()); forest.print();
  38. */
  39. /*
  40. * StopWatch sw1 = new StopWatch(); StopWatch sw2 = new StopWatch();
  41. * byte[] arr1 = Util.nextBytes((int) Math.pow(2, 20), Crypto.sr);
  42. * byte[] arr2 = Util.nextBytes((int) Math.pow(2, 20), Crypto.sr);
  43. *
  44. * sw1.start(); Util.xor(arr1, arr2); sw1.stop();
  45. *
  46. * sw2.start(); new BigInteger(1, arr1).xor(new BigInteger(1,
  47. * arr2)).toByteArray(); sw2.stop();
  48. *
  49. * System.out.println(sw1.toMS()); System.out.println(sw2.toMS());
  50. */
  51. int n = 20;
  52. Integer[] oldArr = new Integer[n];
  53. for (int i = 0; i < n; i++)
  54. oldArr[i] = Crypto.sr.nextInt(50);
  55. int[] pi = Util.randomPermutation(n, Crypto.sr);
  56. int[] pi_ivs = Util.inversePermutation(pi);
  57. Integer[] newArr = Util.permute(oldArr, pi);
  58. newArr = Util.permute(newArr, pi_ivs);
  59. for (int i = 0; i < n; i++) {
  60. System.out.println(oldArr[i] + " " + newArr[i]);
  61. }
  62. }
  63. }