from pwn import * import decimal HOST = "130.192.5.212" PORT = "6647" server = remote(HOST,PORT) n = int(server.recv(1024).strip()) c = int(server.recv(1024).strip()) e = 65537 def to_bytes(m,l=512): return int.to_bytes(m, l=n.bit_length(), byteorder='big') def print_bounds(low, up): print("[" + str(low) + "," + str(up) + "]") decimal.getcontext().prec = n.bit_length() upper_bound = decimal.Decimal(n) lower_bound = decimal.Decimal(0) m = c for i in range(n.bit_length()): m = (pow(2, e, n) * m) % n print(f"M:{m}") server.send(str(m)) server.send(b'\n') bit = server.recv(1024) bit = int(bit) print(f"Bit:{bit}") if bit == 1: lower_bound = (upper_bound + lower_bound) / 2 else: upper_bound = (upper_bound + lower_bound) / 2 #lower_bound = 158107821233229568930984452875602183391823091373912004357129417626853988321867785934374974861174017194049484884 upper_bound = int(upper_bound) print(f"UB:{upper_bound}") print(upper_bound.to_bytes(n.bit_length(),'big').decode())