import sys

path = sys.argv[1] if len(sys.argv) > 1 else "blackbox.bin"
data = open(path, "rb").read()
recs = [data[i:i+16] for i in range(0, len(data), 16)]

type3 = [r for r in recs if len(r) == 16 and r[2] == 3]
print(f"type03 records found: {len(type3)}")

# sort by their internal sequence byte (index 5)
type3.sort(key=lambda r: r[5])

key = bytes.fromhex("deaddeaddeaddead")
out = b""
for r in type3:
    payload = r[6:14]
    dec = bytes(b ^ k for b, k in zip(payload, key))
    print(f"seq={r[5]}  raw={payload.hex()}  dec={dec!r}")
    out += dec

print("\nconcatenated raw decode:", out)
print("as text (strip nulls):", out.replace(b'\x00', b'').decode(errors='replace'))
