07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6 ■ Using Cryptography with Images 173

print()

print('The image has now been decrypted. Review d_ch6_secret_image.jpg')

fo = open("Chapter6\d_ch6_secret_image.jpg", "wb")

fo.write(image)

fo.close()

While the image is now unreadable, it may also throw an error depending

on the software you are using (see Figure 6.2). This isn’t a showstopper, though,

as you can still email the file anywhere and you will not have to worry about

someone decrypting it without the key, which in this case is 42.

Figure 6.2: Error message for e_ch6_secret_image.jpg

Decrypting will reproduce the image without data loss, as shown in Figure 6.3.

This is important to examine as some modes will have some loss. The image

on the left is the original, while the image on the right has been encrypted and

then decrypted. Later, we will examine various encryption modes that work

well on regular files but fail on images. One such example is the use of the ECB

mode discussed shortly.

In the next section, we will start exploring more complex solutions using

cryptographic libraries.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!