Image Encryption and Decryption
* Introduction:
In the past few years, several encryption algorithms based on chaotic systems have been proposed as means to protect digital images against cryptographic attacks. These encryption algorithms typically use relatively small key spaces and thus offer limited security.
Traditional image encryption algorithms such as private key encryption standards (DES and AES), public key standards such as Rivest Shamir Adleman (RSA), and the family of elliptic-curve-based encryption (ECC), as well as the international data encryption algorithm (IDEA), may not be the most desirable candidates for image encryption, especially for fast and real-time communication applications.
* Encryption:
Let πΌπ represent an πΌ -bit gray scale image of the size πΓπ . Here, π¨π represent the pixels values matrix of the image. The steps of encryption algorithm are as follows:
- Generate randomly two vectors πΎπ and πΎπΆ of length π and π , respectively. Element πΎπ (π) and πΎπΆ (π) each take a random value of the set π={0,1,2,β¦,2 πΌ β1} .
- Determine the number of iterations, ITER max , and initialize the counter ITER at 0.
- Increment the counter by one: ITER=ITER+1 .
- For each row π of image πΌ π, (i) compute the sum of all elements in the row π (ii) compute modulo 2 of πΌ(π) , denoted by ππΌ(π)
{iii} row π is left, or right, circular-shifted by πΎπ (π) positions. - For each column π of image apply the same but using πΎπΆ (π).
- Using vector πΎπΆ (π) , the bitwise XOR operator is applied to each row of scrambled image. Same is applied to πΎπ (π) on each columns.
- If ITER=ITER max , then encrypted image is created and encryption process is done.
* Decryption:
The decrypted image, is recovered from the encrypted image and the secret keys, πΎπ , πΎπΆ , and ITERmax as follows in the following,
- Initialize ITER=0.
- Increment the counter by one: ITER=ITER+1.
- The bitwise XOR operation is applied on vector πΎπ and each column of the encrypted image.
- Then by using the πΎπΆ vector, the bitwise XOR operator is applied to each row of image.
- For each column π of the scrambled image, (i) compute the sum of all elements in that column π (ii) compute modulo 2 of π½SCR (π) , denoted by ππ½SCR (π) (iii) column π is down, or up, circular-shifted by πΎπΆ(π) positions according to the value of ππ½SCR (π).
- For each row π of scrambled image the above procedure is repeated.
- If ITER=ITER max , then image πΌs decrypted and the decryption process is done,otherwise, the algorithm branches back to step 2.
* Analysis
- A secure image encryption scheme must have a large key space in order to make brute-force attack practically (computationally) infeasible.
- The encryption key used in our scheme is composed of the (πΎr ,πΎc ,ITER max ) triplet.
- For an πΌ -bit gray-scale image πΌπ of size πΓπ pixels, the vectors πΎr and πΎc can take 2 πβ πΌ and 2 πβ πΌ possible values, respectively.
- For instance, for an 8-bits, scale gray image of size 256Γ256 pixels and ITER max =1 . The key space size is equal to 24096 β216 β101233 , this key space is large enough to resist the attack.


Codebase: https://github.com/hoplite2k/image-encryption-decryption