#!/bin/sh

KEY=00112233445566778899aabbccddeeff
IV=0102030405060708090a0b0c0d0e0f10

for img in pic_original.bmp maodiehuaqiang.bmp DOSBOX.bmp
do
    name=$(basename "$img" .bmp)

    # ECB 加密
    openssl enc -aes-128-ecb -e -in "$img" -out "${name}_ecb_enc.bmp" -K "$KEY"

    # CBC 加密
    openssl enc -aes-128-cbc -e -in "$img" -out "${name}_cbc_enc.bmp" -K "$KEY" -iv "$IV"

    # 修复 ECB 图片头
    head -c 54 "$img" > header.bin
    tail -c +55 "${name}_ecb_enc.bmp" > body.bin
    cat header.bin body.bin > "${name}_ecb_show.bmp"

    # 修复 CBC 图片头
    head -c 54 "$img" > header.bin
    tail -c +55 "${name}_cbc_enc.bmp" > body.bin
    cat header.bin body.bin > "${name}_cbc_show.bmp"
done

rm -f header.bin body.bin
