Created
March 9, 2018 04:11
-
-
Save CameronLonsdale/a2daa927f2556d14b16745a68f6ed430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from PIL import Image | |
from Crypto.Cipher import AES | |
KEY = "YELLOW SUBMARINE" | |
INPUT = "logo.png" | |
OUTPUT = "encrypted.png" | |
def pad(plaintext: bytearray, block_size=AES.block_size): | |
"""PKCS#7 Padding""" | |
num_pad = block_size - (len(plaintext) % block_size) | |
return plaintext + bytearray([num_pad for x in range(num_pad)]) | |
plaintext_img = Image.open(INPUT) | |
cipher = AES.new(KEY, AES.MODE_ECB) | |
encrypted_image = cipher.encrypt(bytes(pad(plaintext_img.tobytes()))) | |
Image.frombytes(plaintext_img.mode, plaintext_img.size, encrypted_image).save(OUTPUT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment