File size: 1,996 Bytes
c03f5ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
decrypt_checkpoints.py — Decrypt Amy .pt.enc checkpoints back to .pt

Usage:
    python decrypt_checkpoints.py <encrypted_dir> <output_dir>
    python decrypt_checkpoints.py ./v1_cache_encrypted ./checkpoints

Requires: pip install cryptography
Key: see DECRYPTION_KEY.md (private, do NOT commit)
"""
import os
import sys
import glob
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

# Paste your key here or set AMY_DECRYPT_KEY env var
KEY_HEX = os.environ.get(
    "AMY_DECRYPT_KEY",
    "44ab060120516fadb0fc1be322d16e4fda0571f041fb534d9a6a0c945d5d9b1e"
)
KEY = bytes.fromhex(KEY_HEX)


def decrypt_file(src_path: str, dst_path: str):
    """Decrypt src_path (.enc) → dst_path (.pt)"""
    aesgcm = AESGCM(KEY)
    raw = open(src_path, "rb").read()
    nonce = raw[:12]
    ct = raw[12:]
    plaintext = aesgcm.decrypt(nonce, ct, None)
    with open(dst_path, "wb") as f:
        f.write(plaintext)
    return len(plaintext)


def decrypt_directory(src_dir: str, dst_dir: str):
    """Decrypt all .pt.enc files in src_dir → dst_dir as .pt"""
    os.makedirs(dst_dir, exist_ok=True)
    files = sorted(glob.glob(os.path.join(src_dir, "*.pt.enc")))
    print(f"Found {len(files)} encrypted files in {src_dir}")
    for i, fpath in enumerate(files):
        name = os.path.basename(fpath).replace(".enc", "")
        dst = os.path.join(dst_dir, name)
        if os.path.exists(dst):
            print(f"  [{i+1}/{len(files)}] SKIP (exists): {name}")
            continue
        size_mb = os.path.getsize(fpath) / 1e6
        print(f"  [{i+1}/{len(files)}] Decrypting {name} ({size_mb:.0f}MB)...", flush=True)
        orig = decrypt_file(fpath, dst)
        print(f"    → {name} ({orig/1e6:.0f}MB)")
    print(f"\nDone. {len(files)} files decrypted to {dst_dir}")


if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("Usage: python decrypt_checkpoints.py <encrypted_dir> <output_dir>")
        sys.exit(1)
    decrypt_directory(sys.argv[1], sys.argv[2])