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 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 не найден")
exit()
alice = json.loads(match.group())
for name in ['p', 'g', 'A']:
val = alice[name]
print(f"\n=== {name} ===")
print(f"Raw: {val}")
if val.startswith('0x'):
hex_str = val[2:]
# Если нечетная длина, добавляем 0
if len(hex_str) % 2 != 0:
hex_str = '0' + hex_str
try:
b = bytes.fromhex(hex_str)
print(f"Bytes (hex): {b.hex()}")
# Пробуем разные кодировки
for enc in ['utf-8', 'ascii', 'latin-1']:
try:
decoded = b.decode(enc)
# Показываем только если есть читаемые символы
printable = ''.join(c if c.isprintable() else '.' for c in decoded)
print(f"Decoded ({enc}): {printable}")
except:
pass
except Exception as e:
print(f"Ошибка bytes.fromhex: {e}")