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')
print(f"[*] Получено:\n{text}\n")
match = re.search(r'\{.*\}', text)
if not match:
print("[-] JSON не найден. Сервер молчит. Попробуй через 5 минут.")
exit()
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}")
# Пробуем разные XOR-комбинации
combos = {
'A': A,
'A^g': A ^ g,
'A^p': A ^ p,
'A^g^p': A ^ g ^ p,
'A^(g+p)': A ^ (g + p),
'A^(g*p)': A ^ (g * p),
'(A-g)^g': (A - g) ^ g,
'(A-p)^p': (A - p) ^ p,
'A//g': A // g,
'A%g': A % g,
'A%p': A % p,
}
print("\n[*] Пробуем XOR-комбинации...")
for name, val in combos.items():
if val <= 0:
continue
try:
b = val.to_bytes((val.bit_length() + 7) // 8, 'big')
decoded = b.decode('utf-8', errors='ignore')
printable = ''.join(c if c.isprintable() else '.' for c in decoded)
if any(c.isdigit() or c in '+-*/' for c in decoded) or 'DUCKERZ' in printable:
print(f" [+] {name}: {printable[:200]}")
except Exception as e:
pass
# Пробуем XOR с маленькими числами (0-255)
print("\n[*] Пробуем XOR с маленькими числами...")
for k in range(1, 256):
val = A ^ k
try:
b = val.to_bytes((val.bit_length() + 7) // 8, 'big')
decoded = b.decode('utf-8', errors='ignore')
if any(c.isdigit() or c in '+-*/' for c in decoded):
printable = ''.join(c if c.isprintable() else '.' for c in decoded)
print(f" [+] A XOR {k}: {printable[:200]}")
except:
pass
s.close()