from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import sys

KEY = b"rK7CcATuZk7LAmhqqU4iBLNmAq8QbK3s"

for path in ["SteamData/SaveData.sav", "SteamData/SubSaveData001001.sav"]:
    with open(path, "rb") as f:
        raw = f.read()
    iv = raw[:16]
    ct = raw[16:]
    c = AES.new(KEY, AES.MODE_CBC, iv=iv)
    pt = unpad(c.decrypt(ct), AES.block_size)
    out = path.replace(".sav", "_decrypted.sav")
    with open(out, "wb") as f:
        f.write(pt)
    print(f"{path}: {len(raw)} enc -> {len(pt)} dec")
    print(f"  First 64 bytes hex:")
    for i in range(0, min(64, len(pt)), 16):
        hexpart = " ".join(f"{b:02X}" for b in pt[i:i+16])
        asciipart = "".join(chr(b) if 32 <= b < 127 else "." for b in pt[i:i+16])
        print(f"  {i:04x}: {hexpart:48s} {asciipart}")
