/
solve.java
84 lines (75 loc) · 3.05 KB
/
solve.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.io.*;
import java.nio.file.*;
public class test {
public static void main(String[] args) throws IOException {
Path path = Paths.get("IceCreamManual.txt");
byte[] manualBytes = Files.readAllBytes(path);
//String s = "lollookatthistextigotfromthemanual";
//byte[] enc = s.getBytes();
byte[] enc = fillMachine(manualBytes);
byte[] loadedBytes = strawberryShuffle(vanillaShuffle(chocolateShuffle(toppings(enc))));
System.out.print("flag{");
for (int i = 0; i < 34; ++i)
System.out.print((char)loadedBytes[i]);
System.out.println('}');
}
public static byte[] fillMachine(byte[] inputIceCream) {
byte[] outputIceCream = new byte[34];
int[] intGredients = {27, 120, 79, 80, 147,
154, 97, 8, 13, 46, 31, 54, 15, 112, 3,
464, 116, 58, 87, 120, 139, 75, 6, 182,
9, 153, 53, 7, 42, 23, 24, 159, 41, 110};
for (int i = 0; i < outputIceCream.length; i++) {
outputIceCream[i] = inputIceCream[intGredients[i]];
}
return outputIceCream;
}
public static byte[] strawberryShuffle(byte[] inputIceCream) {
byte[] outputIceCream = new byte[inputIceCream.length];
for (int i = 0; i < outputIceCream.length; i++) {
outputIceCream[outputIceCream.length - i - 1] = inputIceCream[i];
}
return outputIceCream;
}
public static byte[] vanillaShuffle(byte[] inputIceCream) {
byte[] outputIceCream = new byte[inputIceCream.length];
for (int i = 0; i < outputIceCream.length; i++) {
if (i % 2 == 0) {
outputIceCream[i] = (byte)(inputIceCream[i] - 1);
} else {
outputIceCream[i] = (byte)(inputIceCream[i] + 1);
}
}
return outputIceCream;
}
public static byte[] chocolateShuffle(byte[] inputIceCream) {
byte[] outputIceCream = new byte[inputIceCream.length];
for (int i = 0; i < outputIceCream.length; i++) {
if (i % 2 == 0) {
if (i > 0) {
outputIceCream[i - 2] = inputIceCream[i];
} else {
outputIceCream[outputIceCream.length - 2] = inputIceCream[i];
}
} else {
if (i < outputIceCream.length - 2) {
outputIceCream[i + 2] = inputIceCream[i];
} else {
outputIceCream[1] = inputIceCream[i];
}
}
}
return outputIceCream;
}
public static byte[] toppings(byte[] inputIceCream) {
byte[] outputIceCream = new byte[inputIceCream.length];
byte[] toppings = {8, 61, -8, -7, 58, 55,
-8, 49, 20, 65, -7, 54, -8, 66, -9, 69,
20, -9, -12, -4, 20, 5, 62, 3, -13, 66,
8, 3, 56, 47, -5, 13, 1, -7,};
for (int i = 0; i < outputIceCream.length; i++) {
outputIceCream[i] = (byte)(inputIceCream[i] - toppings[i]);
}
return outputIceCream;
}
}