-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATCSNightmare.java
59 lines (54 loc) · 1.59 KB
/
ATCSNightmare.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
import java.util.*;
public class ATCSNightmare {
public static String stackAttack(String in) {
Stack<Character> s = new Stack<>();
for (char c: in.toCharArray())
s.push(c);
String res = "";
int i = 0;
while (!s.isEmpty()) {
res += (char)(s.pop() - i);
i = (i + 1) % 4;
}
return res;
}
public static String recurses(String in, String out, int i) {
if (in.isEmpty())
return out;
String res = out;
if (i == 0)
res += in.charAt(i);
else
res = in.charAt(i) + res;
if (i == 0)
return recurses(in.substring(1), res, 1);
return recurses(in.charAt(0) + in.substring(2), res, 0);
}
public static String linkDemLists(String in) {
LinkedList<Character> lin = new LinkedList<>();
for (char x: in.toCharArray())
lin.add(x);
String res = "";
ListIterator<Character> iter = lin.listIterator(in.length()/2);
while (iter.hasNext())
res += iter.next();
iter = lin.listIterator(in.length()/2);
while (iter.hasPrevious())
res += iter.previous();
return res;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the flag: ");
String f = in.next();
if (f.length() == 34 && f.substring(0, 4).equals("flag") && f.charAt(33) == '}') {
f = f.substring(5, 33);
if (linkDemLists(recurses(stackAttack(f), "", 1)).equals("20_a1qti0]n/5f642kb\\2`qq4\\0q"))
System.out.println("Congrats! That is your flag!");
else
System.out.println("Sorry, that is incorrect.");
} else
System.out.println("Sorry, that is incorrect.");
in.close();
}
}