Question: In this task, we are to explore a simple image encryption. An example of an image encryption is written in Python as follows: # Simple

In this task, we are to explore a simple image encryption. An example of an image encryption is
written in Python as follows:
# Simple Python Code
ifile, ofile = sys.arg[1:3]
with open(ifile,"rb") as reader:
with open(ofile,"wb+") as writer:
image_data = reader.read()
header, body = image_data[:54], image_data[54:]
body += b"\x00"*(16-(len(body)%16))
writer.write(header + aesEncryptor.update(body))
Your first task is to understand the idea of the above code. This is a very basic AES encrypting
program, and the key that is used for encrypting it does not really matter much. It means, you
can just choose any random key for this, or just use a fixed test key. We will need to first read
a binary file, encrypt everything except the first 54 bytes, and then write it out to a new file. The
reason we are not encrypting the first 54 bytes is because this program is going to encrypt the
contents of a bitmap file (BMP) and the header is 54 bytes in length. You should try to use an
image editor of your choice to create a large image with text that takes up most of the space.
Then save the encrypted file to something encrypted_image.bmp, then open the file with an image
viewer. Finally, write a decryption program to decrypt the encrypted image. If you can see the
original image, then it means you have done this first step correctly.
The main idea of this task is to understand the difference between AES-CBC and AES-CTR
mode. Do the following steps.
First introduce an error into the ciphertext and decrypt the modified bytes. Try for example
picking the byte right in the middle of the encrypted image data and setting it to 0. After corrupting the data, call the decryption program and view the restored image. Compare the impact
between CBC and CTR mode. Based on this experiment, write a report to demonstrate the difference and impact between CBC and CTR mode.
Hints: You can try with an all-white image. If you still cannot figure it out, change 50 bytes or
so to figure out where the changes are happening. Once you find where the changes are happening, go back to changing a single byte to view the differences between CTR and CBC. Can you
explain what is happening there clearly in the report?
You can choose to use C++ or Java to implement this part too. It is not necessary to use Python.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!