# Trickery Index

This time, the task is very simple: after completing an obligatory proof of work (a basic SHA256 bruteforce) and waiting a couple seconds we are presented with a couple of pretty big integers, `a` and `b`. So what’s the mission?

``````Your mission is to find x, y such that x**6 + a * y**6 = b
``````

Okay. Do we have a plan?

Why of course we do!

So let’s get our hands dirty and dive into some sympy docs! The function we need can be found rather easily, and that other thing, the true cube root algorithm, we can nick from the good people over at StackOverflow.

Here’s the code then!

``````import socket
import hashlib
import itertools
import string
from mpmath import cbrt, im

from sympy.abc import x, y

def true_cbrt(n):
lo = 0
hi = n
while lo < hi:
mid = (lo+hi)//2
if mid**3 < n:
lo = mid+1
else:
hi = mid
return lo

def recvuntil(s, stop):
data = ""
data += s.recv(1)
while not data.endswith(stop):
data += s.recv(1)
return data

s = socket.socket()
s.connect(('146.185.143.84', 13245))

recvuntil(s,"Submit")
pow_target = s.recv(1024)[-7:-1]

# proof of work
pow = ""
for word in itertools.product(string.printable, repeat=5):
if hashlib.sha256(''.join(word)).hexdigest()[-6:] == pow_target:
pow = ''.join(word)
break

s.send(pow + '\n')

data = recvuntil(s, ':)')
print data

solutions = diop_quadratic(x**2 + a*(y**2) - b)

for sol in solutions:
if im(cbrt(sol)) == 0 and im(cbrt(sol)) == 0:
out_x = true_cbrt(sol)
out_y = true_cbrt(sol)
break

s.send("%d %d\n" % (out_x, out_y))
print s.recv(1024)
print s.recv(1024)
``````

Let’s run it and wait a bit…

``````(ctf) tr@karabut.com:~/work/asisquals17\$ python crows.py