Загрузка данных


import socket
import json
import re

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10.0)
s.connect(('tasks.duckerz.ru', 30009))

# Читаем
data = b""
try:
    while True:
        chunk = s.recv(4096)
        if not chunk:
            break
        data += chunk
        if b"Send to Bob:" in data:
            break
except socket.timeout:
    pass

text = data.decode('utf-8', errors='ignore')
match = re.search(r'\{.*\}', text)
if match:
    alice = json.loads(match.group())
    p = int(alice['p'], 16)
    g = int(alice['g'], 16)
    A = int(alice['A'], 16)
    
    print(f"[*] p = {p}")
    print(f"[*] g = {g}")
    print(f"[*] A = {A}")
    
    # Перебираем x от 1 до 1_000_000
    print("[*] Перебираем x...")
    for x in range(1, 1_000_000):
        if pow(g, x, p) == A:
            print(f"[+] НАЙДЕНО! x = {x}")
            s.sendall((str(x) + "\n").encode())
            
            # Читаем ответ
            try:
                resp = s.recv(4096).decode('utf-8', errors='ignore')
                print(f"[+] Ответ: {resp}")
            except:
                print("[-] Таймаут")
            break
        
        if x % 100000 == 0:
            print(f"[*] Проверено {x}...")
    else:
        print("[-] x не найден в пределах 1_000_000")