Earthcomputer

Untitled

Mar 27th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.12 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(bvec, mm1);
  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.                 for (int k = 0; k < 2696; k++)
  30.                     rand.nextDouble();
  31.                 detectorArray[j] = getDetectorOutput(rand.nextDouble() * 2 * Math.PI);
  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[k][j] & 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(v, mm1, j);
  49.                 val = val.subtract(toBigInt48(bvec[j]));
  50.                 val = val.shiftRight(48);
  51.                 penultimateVector[j] = val.longValue();
  52.             }
  53.  
  54.             //System.out.println(Arrays.toString(penultimateVector));
  55.             long seed = dot(m6, penultimateVector) & 0xffffffffffffL;
  56.             for (int j = 0; j < 1; j++) {
  57.                 //seed = ((seed - 0xbL) * 0xdfe05bcb1365L) & 0xffffffffffffL;
  58.                 seed = (seed * 0x5deece66dL + 0xbL) & 0xffffffffffffL;
  59.             }
  60.             System.out.println("Expected: " + getSeed(rand) + ", actual: " + seed);
  61.         }
  62.  
  63.     }
  64.  
  65.     private static BigInteger toBigInt48(long n) {
  66.         if ((n & 0x800000000000L) != 0)
  67.             return BigInteger.valueOf(n | 0xffff000000000000L);
  68.         else
  69.             return BigInteger.valueOf(n & 0xffffffffffffL);
  70.     }
  71.  
  72.     private static BigInteger dotBig(long[] v, long[][] mat, int col) {
  73.         BigInteger result = BigInteger.ZERO;
  74.         for (int i = 0; i < v.length; i++) {
  75.             result = result.add(BigInteger.valueOf(v[i] & 0xffffffffffffL).multiply(toBigInt48(mat[i][col])));
  76.         }
  77.         return result;
  78.     }
  79.  
  80.     private static long dot(long[] a, long[] b) {
  81.         long result = 0;
  82.         for (int i = 0; i < a.length; i++)
  83.             result += a[i] * b[i];
  84.         return result;
  85.     }
  86.  
  87.     private static long[] matmult(long[] vec, long[][] mat) {
  88.         long[] result = new long[mat.length];
  89.         for (int i = 0; i < mat.length; i++) {
  90.             for (int j = 0; j < mat.length; j++) {
  91.                 result[i] += vec[j] * mat[j][i];
  92.             }
  93.         }
  94.         return result;
  95.     }
  96.  
  97.     private static long getSeed(Random rand) {
  98.         try {
  99.             Field field = Random.class.getDeclaredField("seed");
  100.             field.setAccessible(true);
  101.             return ((AtomicLong) field.get(rand)).get();
  102.         } catch (ReflectiveOperationException e) {
  103.             e.printStackTrace();
  104.             return 0;
  105.         }
  106.     }
Advertisement
Add Comment
Please, Sign In to add comment