forked from google/google-ctf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchal.py
52 lines (41 loc) · 936 Bytes
/
chal.py
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
#!/usr/bin/python3 -u
SBOX = {
(0, 0): (0, 0),
(0, 1): (1, 0),
(0, 2): (0, 1),
(1, 0): (1, 1),
(1, 1): (0, 2),
(1, 2): (1, 2),
}
def step(l1, l2):
if l1[0] == 0:
l1.pop(0)
else:
l2.insert(0, 1)
l1.append(0)
for i in range(len(l1)):
l1[i], l2[i] = SBOX[l1[i], l2[i]]
while l1[-1] == l2[-1] == 0:
l1.pop()
l2.pop()
def count(l1, l2):
n = 0
while l1 + l2 != [1, 0]:
step(l1, l2)
n += 1
return n
def read_lists():
l1 = [ord(c) % 2 for c in input("> ")]
l2 = [ord(c) % 3 for c in input("> ")]
assert len(l1) < 24, "too big"
assert len(l1) == len(l2), "must be same size"
return l1, l2
if __name__ == "__main__":
l1, l2 = read_lists()
c = count(l1, l2)
if c > 2000:
print("You win")
print(open("flag.txt").read())
else:
print("Too small :(")
print(c)