from pwn import * import re import sympy import numpy as np port = 2236 # context.log_level = 'debug' #will print all input and output for debugging purposes conn = remote("ctf.k3rn3l4rmy.com",port) #enter the address and the port here as strings. For example nc 0.0.0.0 5000 turns into remote('0.0.0.0', 5000) defget_input(): #function to get one line from the netcat input = conn.recvline().strip().decode() returninput defparse(my_poly): ''' TODO: Parse polynomial For example, parse("x^3 + 2x^2 - x + 1") should return [1,2,-1,1] ''' # my_poly = "2*x**2+7*x-3" my_poly = my_poly.replace("^", "**").replace(my_poly[0], "*x").replace("*x", my_poly[0], 1) x = sympy.Symbol('x') my_poly = sympy.polys.polytools.poly_from_expr(my_poly)[0] coeffs = my_poly.coeffs() return coeffs for _ inrange(4): get_input() #ignore challenge flavortext for i inrange(100): type = get_input() coeffs = parse(get_input()) print(coeffs)
ans = 0 if'sum of the roots'intype: #TODO: Find answer print("sum of the roots") ans = -1*coeffs[1] elif'sum of the reciprocals of the roots'intype: #TODO: Find answer print("sum of the reciprocals of the roots") ans = -1*coeffs[-2]//coeffs[-1] elif'sum of the squares of the roots'intype: #TODO: Find answer print("sum of the squares of the roots") ans = coeffs[1]**2-2*coeffs[2] print(ans) conn.sendline(str(ans)) #send answer to server get_input() conn.interactive() #should print flag if you got everything right