HITCONCTF - cclemon
Challenge Description
1
2
3
4
Speak in π
Author: david942j
Solved: 24/286
Inspection
Opening the file, we see that there is some byte code, it resembles python byte code, so we start reversing it as if it is in python.
Simulation
With that, we slowly build up a python version of the code, as shown here in solve.py, we then run it with pypy3 to receive the flag. The initial version doesnβt produce the right answer, so we need to recheck each comparison and make sure the python script is running exactly the same thing as the byte code
hitcon{42978937495235537896}
After the competition, we learn that the code is actually in lemon language, hence the challenge title - cclemon
Appendix - solve.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
53
54
55
56
57
58
59
60
61
62
63
64
g0 = 68694329
def w():
global g0
g0 = (g0 * 1259409 + 321625345) % 4294967296
return g0
g1 = w
class A:
def __init__(self, n):
self.a = []
i = 0
while i < n:
self.a.append(g1())
i += 1
return
def r(self, x, y):
if x <= y:
while x < y:
self.s(x, y)
x += 1
y -= 1
return
else:
return self.r(y, x)
def s(self, x, y):
l2 = self.a[x]
self.a[x] = self.a[y]
self.a[y] = l2
return
def o(self, x, y, val):
if x > y:
return self.o(y, x, val)
else:
i = x
while i <= y:
self.a[i] ^= val
i += 1
return
a = A(200000)
i = 0
while i < 200000 * 5:
c = g1() % 3
x = g1() % 200000
y = g1() % 200000
if c == 0:
a.r(x, y)
elif c == 1:
a.s(x, y)
elif c == 2:
a.o(x, y, g1())
i += 1
i = 0
sum = 0
while i < 200000:
sum = sum + a.a[i] * (i + 1)
i += 1
print("hitcon{" + str(sum) + "}")