import socket
import json
import re
HOST = 'tasks.duckerz.ru'
PORT = 30009
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(20.0)
s.connect((HOST, PORT))
data = b""
try:
while b"Send to Bob:" not in data:
chunk = s.recv(4096)
if not chunk:
break
data += chunk
except socket.timeout:
pass
text = data.decode('utf-8', errors='ignore')
match = re.search(r'\{.*\}', text)
alice = json.loads(match.group())
p = int(alice['p'], 16)
g = int(alice['g'], 16)
A = int(alice['A'], 16)
print(f"[*] p = {p} ({p.bit_length()} бит)")
print(f"[*] g = {g}")
print(f"[*] A = {A}")
# Наш ключ
c = 1337
C = pow(A, c, p) # <--- ВОТ ЭТА ФОРМУЛА!
print(f"[*] c = {c}")
print(f"[*] C = pow(A, c, p) = {C}")
# Отправляем
payload = json.dumps({"C": C})
print(f"[*] Отправляем: {payload[:100]}...")
s.sendall((payload + "\n").encode())
# Читаем ответ
s.settimeout(15.0)
try:
while True:
resp = s.recv(4096)
if not resp:
print("[-] Соединение закрыто")
break
decoded = resp.decode('utf-8', errors='ignore')
print(f"[+] Ответ: {decoded}")
if "DUCKERZ{" in decoded:
print(f"\n[!!!] ФЛАГ: {decoded}\n")
break
except socket.timeout:
print("[-] Таймаут")
s.close()