less than 1 minute read

With googling, I could find the complex equation is Heron's formula. And I wrote sage code like below.

#heron.sage

a = RDF(62791383142154.0)

b, c = var('b c')
s = (a+b+c)/2
S2 = (s*(s-a)*(s-b)*(s-c))

x = RDF(19400354808065.543)
y = RDF(47770539528273.91)

eq1 = (4*S2)/((a+b+c)^2) == x^2
eq2 = ((a*b*c)^2)/(16.0*S2) == y^2

print solve([eq1, eq2], [b, c], solution_dict=True)

result is,

[{c: 0, b: -62791383142154}, {c: -53018765127556.0, b: 12275658851513.0}, {c: 86252903146790.0, b: -38002520546342.0}, {c: 12275658851513.0, b: -53018765127556.0}, {c: 70802074077084.0, b: 95523798483319.0}, {c: 38666191841930.4 - 51392812865178.7I, b: 38666191841930.3 + 51392812865178.7I}, {c: 38666191841930.4 + 51392812865178.7I, b: 38666191841930.3 - 51392812865178.7I}, {c: 95523798483318.0, b: 70802074077034.0}, {c: -38002520546336.0, b: 86252903146787.0}, {c: -62791383142154, b: 0}]

I thought I got value of b and c, but there is inaccurate. After a lots of digging, I just tried to brute force attack with below code.

#bf.py
import os

a = 62791383142154.0
b = 70802074077034.0
c = 95523798483318.0
for i in range(-5, 5):
        for j in range(-5, 5):
                key = "flag{\%x-\%x-\%x}"%(a,b+i,c+j)
                print key
                os.system("echo \""+key+"\" | ./Elements")

'''
.
.
flag{391bc2164f0a-4064e4798769-56e0de138174}
flag{391bc2164f0a-4064e4798769-56e0de138175}
flag{391bc2164f0a-4064e4798769-56e0de138176}
Congratz, input is your flag
flag{391bc2164f0a-4064e4798769-56e0de138177}
flag{391bc2164f0a-4064e4798769-56e0de138178}
flag{391bc2164f0a-4064e4798769-56e0de138179}
.
.
'''

The flag is flag{391bc2164f0a-4064e4798769-56e0de138176}