-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflag.java
55 lines (47 loc) · 1.59 KB
/
flag.java
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
53
54
55
import java.io.Console;
public class Oracle {
private static final int FLAG_LENGTH = 42;
private static final byte[] CHECK = new byte[] {
48, 6, 122, -86, -73, -59, 78, 84, 105, -119,
-36, -118, 70, 17, 101, -85, 55, -38, -91, 32,
-18, -107, 53, 99, -74, 67, 89, 120, -41, 122,
-100, -70, 34, -111, 21, Byte.MIN_VALUE, 78, 27, 123, -103,
36, 87 };
private static byte[] numbers;
private static void firstPass() {
for (byte b = 0; b < 42; b++)
numbers[b] = (byte)(numbers[b] ^ 3 * b * b + 5 * b + 101 + b % 2);
}
private static void secondPass() {
byte[] arrayOfByte = new byte[42];
for (byte b = 0; b < 42; b++)
arrayOfByte[b] = (byte)(numbers[(b + 42 - 1) % 42] << 4 | (numbers[b] & 0xFF) >> 4);
numbers = arrayOfByte;
}
private static void thirdPass() {
for (byte b = 0; b < 42; b++)
numbers[b] = (byte)(numbers[b] + 7 * b * b + 31 * b + 127 + b % 2);
}
private static void fail() {
System.out.println("\nThat's not the flag. Try again.");
System.exit(1);
}
public static void main(String[] paramArrayOfString) {
Console console = System.console();
//numbers = console.readLine("Enter flag: ", new Object[0]).getBytes();
numbers = paramArrayOfString[0].getBytes();
if (numbers.length != 42)
fail();
firstPass();
secondPass();
thirdPass();
int i = 0;
for (byte b = 0; b < 42; b++) {
System.out.print(numbers[b]+" ");
i |= CHECK[b] ^ numbers[b];
}
if (i != 0)
fail();
System.out.println("\nGood job. You found the flag!");
}
}