-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHiddenClass.java
More file actions
52 lines (46 loc) · 1.71 KB
/
HiddenClass.java
File metadata and controls
52 lines (46 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Random;
public class HiddenClass {
private final DebugRand rand = new DebugRand();
private final long before = System.nanoTime();
private final Random randGen = new Random();
private final long after = System.nanoTime();
private final long secretKey;
private final int secret2;
public HiddenClass() {
secret2 = rand.nextInt(20);
secretKey = rand.nextLong();
System.out.println("[HiddenClass] Shuffling...");
shuffleRand();
ReplicatedRandom rr = new ReplicatedRandom();
rr.replicateState(randGen.nextLong());
long randSeed = rr.initSeed;
System.out.println("Key1: " + secretKey);
System.out.println("Key2: " + secret2);
System.out.println("Before: " + before);
System.out.println("During: " + randSeed);
System.out.println("After: " + after);
System.out.printf(
"Diff: ->R: %s, R->: %s\n",
randSeed - before,
after - randSeed
);
long guess =
rand.getInitialSeed()
^ (8682522807148012L * 1181783497276652981L)
^ 0x5DEECE66DL;
System.out.printf(
"Guess transforms: %s -> %s -> %s\n",
rand.getInitialSeed(),
rand.getInitialSeed() ^ (8682522807148012L * 1181783497276652981L),
guess
);
System.out.println("Guess: " + guess + " = " + rand.checkSeed(guess, 20, secret2));
}
private void shuffleRand() {
for (int i = 0; i < 10; i++)
rand.nextLong();
}
public boolean guessSecretKey(long key) {
return secretKey == key || key == secret2;
}
}