#!/usr/bin/env bash
set -euo pipefail
outdir="${1:-task5_out}"
byte_index="${2:-55}"
mask="${3:-1}"
python3 - "$outdir" "$byte_index" "$mask" <<'PY'
import sys
from pathlib import Path
outdir=Path(sys.argv[1])
idx=int(sys.argv[2])-1
mask=int(sys.argv[3],0)
for name in ["task5_ecb","task5_cbc","task5_cfb","task5_ofb"]:
    src=outdir/f"{name}.bin"
    dst=outdir/f"{name}_corrupt.bin"
    data=bytearray(src.read_bytes())
    data[idx]^=mask
    dst.write_bytes(data)
PY
