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


import socket
import json
import re
import time

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
        # Если видим "Send to Bob:", прекращаем читать
        if b"Send to Bob:" in data:
            break
except socket.timeout:
    pass

text = data.decode('utf-8', errors='ignore')
print(f"[*] Получено:\n{text}\n")

# Парсим JSON
match = re.search(r'\{.*\}', text)
if match:
    alice = json.loads(match.group())
    A_dec = int(alice['A'], 16)
    p_dec = int(alice['p'], 16)
    g_dec = int(alice['g'], 16)
    
    print(f"[*] A (dec) = {A_dec}")
    print(f"[*] p (dec) = {p_dec}")
    print(f"[*] g (dec) = {g_dec}")
    
    # Пробуем отправить A как ответ
    answer = str(A_dec)
    print(f"[*] Отправляем: {answer[:50]}...")
    s.sendall((answer + "\n").encode())
    
    # Слушаем ответ 10 секунд
    print("[*] Ждем ответ...")
    try:
        while True:
            resp = s.recv(4096)
            if not resp:
                print("[-] Соединение закрыто")
                break
            print(f"[+] Ответ: {resp.decode('utf-8', errors='ignore')}")
    except socket.timeout:
        print("[-] Таймаут - сервер молчит")