import math import re import socket import time HOST = "challenge01.root-me.org" PORT = 52002 def solve_prompt(prompt: str) -> str: match = re.search( r"square root of\s*(\d+)\s*and multiply by\s*(\d+)", prompt, re.IGNORECASE, ) if not match: raise ValueError("Unsupported challenge prompt") left = int(match.group(1)) right = int(match.group(2)) return f"{math.sqrt(left) * right:.2f}" def main() -> None: conn = socket.create_connection((HOST, PORT), timeout=2) start_time = time.monotonic() try: prompt = conn.recv(4096).decode(errors="replace") print(prompt, end="") answer = solve_prompt(prompt) conn.sendall((answer + "\n").encode()) result = conn.recv(4096).decode(errors="replace") print(result, end="") finally: conn.close() elapsed = time.monotonic() - start_time print(f"\nConnection lifetime: {elapsed:.3f}s") if __name__ == "__main__": main()