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 181

with the same encryption key. The decryption process is the reverse. When

using the ECB mode process, identical blocks of plaintext will be encrypted

the same and will yield identical blocks of ciphertext or an encrypted image.

While the weaknesses of the cipher mode may not be initially apparent, when

we examine the mode in image cryptography, a major security vulnerability

appears. In Figure 6.6, you will see the difference between the ECB mode

versus the other modes that are available.

Figure 6.6: Image encryption modes

Exploring a Simple ECB Mode Example

For our first example, we will examine how to produce the ECB mode encrypted

image. First, we start out with a bitmap file that has a distinct pattern, as shown

in Figure 6.7.

Figure 6.7: Plane image in BMP format

The first step is to import the library and set a key. For this example, we will

use a 16-byte key, although 24-byte and 32-byte keys are supported:

>>> from Crypto.Cipher import AES

>>> key = b"aaaabbbbccccdddd"

>>> cipher = AES.new(key, AES.MODE_ECB)

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

Saved successfully!

Ooh no, something went wrong!