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


import socket
import json
import re

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

# Читаем приветствие
data = s.recv(4096).decode('utf-8').strip()
print(f"[*] Получено: {data}")

# Парсим JSON
match = re.search(r'\{.*\}', data)
if match:
    alice = json.loads(match.group())
    A_hex = alice['A']
    A_dec = int(A_hex, 16)
    print(f"[*] A (dec) = {A_dec}")
    
    # Отправляем A как ответ
    s.sendall((str(A_dec) + "\n").encode())
    print(f"[*] Отправили A как число")
    
    # Слушаем ответ
    try:
        resp = s.recv(4096).decode('utf-8').strip()
        print(f"[+] Ответ: {resp}")
    except socket.timeout:
        print("[-] Таймаут. Сервер молчит.")