Question
I wanted to know if I can decrypt this image that uses AES ECBand CBC In PYTHON. The ECB Method is used in below code,
I wanted to know if I can decrypt this image that uses AES ECBand CBC In PYTHON. The ECB Method is used in below code, but i wanta decryption method for cbc also. Please make sure the sameencryption is used. please provide a working code for thedecryption part. Code used for encryption is (Code done in visualstudios)
filename = "image.jpg"
filename_out = "EncryptedAES"
key = "aaaabbbbccccdddd"
def pad(data):
return data + b"x00"*(16-len(data)%16)
def convertRGB(data):
r, g, b = tuple(map(lambda d: [data[i] for i inrange(0,len(data)) if i%3==d], [0,1,2]))
pixels = tuple(zip(r,g,b))
return pixels
def process_image(filename):
im = Image.open(filename)
data = im.convert("RGB").tobytes()
original = len(data)
new = convertRGB(aes_ecb_encrypt(key, pad(data))[:original])
im2 = Image.new(im.mode, im.size)
im2.putdata(new)
im2.save(filename_out+"."+"png", "png")
def aes_ecb_encrypt(key, data, mode=AES.MODE_ECB):
IV = "A"*16
aes = AES.new(key.encode('utf-8'), mode)
new_data = aes.encrypt(data)
return new_data
process_image(filename)
When I put the command process_image('imagefilename.jpg'), i getan encrypted form of image with AES. I need the decryption processfor this method. This code directly works to produce an AESencrypted output
Step by Step Solution
3.47 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
from hashlib import md5 from base64 import b64decode from base64 import b64encode from CryptoCiph...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started