Advertisement
Earthcomputer

Untitled

Mar 27th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.52 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.  
  3.         initialHeight = 26;
  4.         launchTntCount = 7;
  5.         generateDetectorCircle();
  6.         long[] lut = new long[detectors.size()];
  7.         for (int i = 0; i < lut.length; i++)
  8.             lut[i] = getUpperSeedBound(i);
  9.  
  10.         final long a = 0x97be9f880aa9L;
  11.         final long b = 0xeac471130bcaL;
  12.         long[] bvec = {0xc8fbaf16b114L, 0xc2a36898b9feL, 0x13e60619c078L, 0xe7244157cb02L, 0x3771906241cL, 0x47d6c669fa46L, 0L};
  13.         final long[] m6 = {0xff7392795dd6L, 0x1184f9b300L, 0xff79d1d659aeL, 0xff62f08153d5L, 0xfe64fe5e8622L, 0x24beb7ecc11L, 0x30c38f7adcL};
  14.         final long[][] mm1 = {
  15.                 {-26, -81, -16, 50, 14, 22, -76},
  16.                 {-117, 4, -42, -45, -20, -61, -32},
  17.                 {3, 79, 1, 92, 5, 26, 8},
  18.                 {18, 28, 48, 53, -92, -33, -33},
  19.                 {43, 63, -68, -10, 33, 18, -57},
  20.                 {-21, -6, 91, -19, 56, 51, -12},
  21.                 {-44, 25, -6, -1, -44, 65, 34}
  22.         };
  23.         bvec = matmult(mm1, bvec);
  24.  
  25.         for (int i = 0; i < 100; i++) {
  26.             Random rand = new Random();
  27.             int[] detectorArray = new int[7];
  28.             for (int j = 0; j < 7; j++) {
  29.                 detectorArray[j] = getDetectorOutput(rand.nextDouble());
  30.                 for (int k = 0; k < 2696; k++)
  31.                     rand.nextDouble();
  32.             }
  33.  
  34.             long[] penultimateVector = new long[7];
  35.             for (int j = 0; j < 7; j++) {
  36.                 long[] v = new long[7];
  37.                 for (int k = 0; k < 7; k++) {
  38.                     int detectorId = detectorArray[k];
  39.                     if ((mm1[j][k] & 0x800000000000L) != 0) { // if it's negative mod 2^48
  40.                         detectorId--;
  41.                         if (detectorId < 0)
  42.                             detectorId += detectors.size();
  43.                         v[k] = lut[detectorId] & ~((1L << (48 - 26)) - 1);
  44.                     } else {
  45.                         v[k] = lut[detectorId];
  46.                     }
  47.                 }
  48.                 BigInteger val = dotBig(mm1[j], v);
  49.                 val = val.subtract(BigInteger.valueOf(bvec[j]));
  50.                 val = val.shiftRight(48);
  51.                 penultimateVector[j] = val.longValue();
  52.             }
  53.  
  54.             long seed = dot(m6, penultimateVector) & 0xffffffffffffL;
  55.             System.out.println("Expected: " + getSeed(rand) + ", actual: " + seed);
  56.         }
  57.     }
  58.  
  59.     private static BigInteger dotBig(long[] a, long[] b) {
  60.         BigInteger result = BigInteger.ZERO;
  61.         for (int i = 0; i < a.length; i++) {
  62.             result = result.add(BigInteger.valueOf(a[i] & 0xffffffffffffL).multiply(BigInteger.valueOf(b[i] & 0xffffffffffffL)));
  63.         }
  64.         return result;
  65.     }
  66.  
  67.     private static long dot(long[] a, long[] b) {
  68.         long result = 0;
  69.         for (int i = 0; i < a.length; i++)
  70.             result += a[i] * b[i];
  71.         return result;
  72.     }
  73.  
  74.     private static long[] matmult(long[][] mat, long[] vec) {
  75.         long[] result = new long[mat.length];
  76.         for (int i = 0; i < mat.length; i++)
  77.             result[i] = dot(mat[i], vec);
  78.         return result;
  79.     }
  80.  
  81.     private static long getSeed(Random rand) {
  82.         try {
  83.             Field field = Random.class.getDeclaredField("seed");
  84.             field.setAccessible(true);
  85.             return ((AtomicLong) field.get(rand)).get();
  86.         } catch (ReflectiveOperationException e) {
  87.             e.printStackTrace();
  88.             return 0;
  89.         }
  90.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement