from Crypto.Cipher import AES
key = b"aaaabbbbccccdddd"
cipher = AES.new(key, AES.MODE_ECB)
# Szyfrowanie w trybie ECB
with open("./samolot.bmp", "rb") as f:
    byteblock = f.read()

pad = len(byteblock)%16 * -1
byteblock_trimmed = byteblock[64:pad]
ciphertext = cipher.encrypt(byteblock_trimmed)
ciphertext = byteblock[0:64] + ciphertext + byteblock[pad:]

with open("./e_samolot_ecb.bmp", "wb") as f:
    f.write(ciphertext)

# Odszyfrowywanie  
with open("./e_samolot_ecb.bmp", "rb") as f:
    byteblock = f.read()

pad = len(byteblock)%16 * -1
byteblock_trimmed = byteblock[64:pad]
plaintext = cipher.decrypt(byteblock_trimmed)
plaintext = byteblock[0:64] + plaintext + byteblock[pad:]

with open("./d_samolot_ecb.bmp", "wb") as f:
    byteblock = f.write(plaintext)

print("Gotowe")
