0% found this document useful (0 votes)
43 views3 pages

HDCP Key in Image Encryption Process

This document summarizes a cryptography project that implements image encryption and decryption using AES and visual cryptography. The encryption process takes an input image, encodes it to bytes, encrypts it with AES-256 using a hashed key, and further encrypts the ciphertext using a two-layer Caesar cipher trained on key image splits. Decryption reverses these steps to recover the original image. The code is implemented in Python using various libraries and runs via Jupyter Notebook.

Uploaded by

Uday Kiran Reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

HDCP Key in Image Encryption Process

This document summarizes a cryptography project that implements image encryption and decryption using AES and visual cryptography. The encryption process takes an input image, encodes it to bytes, encrypts it with AES-256 using a hashed key, and further encrypts the ciphertext using a two-layer Caesar cipher trained on key image splits. Decryption reverses these steps to recover the original image. The code is implemented in Python using various libraries and runs via Jupyter Notebook.

Uploaded by

Uday Kiran Reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Cryptography Project

By Riya Gupta (17BCS026)

Implementation of Image Encryption using Advanced Encryption Standard (AES)

Implementation of IEEE Paper: A Novel Image Encryption Algorithm using AES and Visual Cryptography,
2016 2nd International Conference on Next Generation Computing Technologies, Dehradun, India

Language used: Python 3.7.4 on Jupyter Notebook (Anaconda)


Libraries used: base64, hashlib, [Link], [Link], numpy, cv2 and sklearn.linear_model

Encryption
Input: An Image and a key (string stored in a text file)
Method:
1. The image is taken as input then read and encoded using base64. Therefore, image is converted
into bytes. Now this data in bytes is decoded in utf-8 to be used as a string.
2. The key, K is read and then hashed using Secure Hash Algorithm – 256 bit (SHA256).
3. The image string is encrypted by AES-256 into cipher text using the hashed key generated in
step 2.
4. Now we convert the original key, K is converted into an image and the split into 2 images, P and
R.
a. A new image C of size(w,h) is initialized as blank, where w = character support for key
file (default: 255) and h = number of characters in key, K.
b. For each row, i in the height of image C, we find a value j which is equal to the ASCII
value of the i-th character in key, K.
c. All the values at positions less than j in a row in C is fed with value 0, i.e., black.
d. Each pixel in R takes a random value between 0 and 1.
e. Now each pixel in P takes a value that is an XOR of R and C at that pixel position, i.e.,
P[i][j] = R[i][j] XOR C[i][j].
5. Encrypting the cipher text further:
a. Two-layer Caesar cipher by training a linear regression model by trained by dataset
generated from images P and R.
b. For X values of linear regression model, there are 2 columns of x’s. Each column having
alternate P row’s sum. All values collected in dataframe xdf.
c. For Y values of linear regression model, there are 2 columns of y’s. Each column having
alternate R row’s sum. All values collected in dataframe ydf.
d. Now dataframes xdf and ydf are fitted into the linear regression model.
e. For prediction, we create another dataframe of 2 columns of z’s. Each column having
alternate C row’s sum. Sum of each column is taken. This gives two values that shall be
used in predicting through our linear regression model.
f. On prediction another 2 values are generated, we take mod 26 of them and store as x
and y.
g. Now for each character in cipher text of original image we find ascii value then add x
and subtract y. Then convert the gotten value back to character and append to a string.
h. The result string is our final cipher text.
Output: cipher text stored in a text file (.txt) and PNG images P and R which are splits of our key image.
This output is sent for decryption.

Decryption
Input: cipher text stored in a text file (.txt) and PNG images P and R which are splits of our key image.
Method:
1. Images R and P are read.
2. We find out the values of h and w from the dimensions of P (or R).
3. A new image, CK is created of size(w,h). Each pixel of CK is the XORed value of P and R at that
pixel position.
4. Now a blank key, K1 of length h is created.
5. For each row in CK,
a. We count the number of 0’s, i.e., black pixels.
b. This count is converted to the corresponding ACSII character and append to K1.
6. K1 which is a list is converted into string. (K1 is same as the key, K that was used in the process
of encryption)
7. The key, K1 is hashed using Secure Hash Algorithm – 256 bit (SHA256).
8. The cipher text is read and stored as a list split by space.
9. Decrypting the cipher text:
a. Two-layer Caesar cipher by training a linear regression model by trained by dataset
generated from images P and R.
b. For X values of linear regression model, there are 2 columns of x’s. Each column having
alternate P row’s sum. All values collected in dataframe xdf.
c. For Y values of linear regression model, there are 2 columns of y’s. Each column having
alternate R row’s sum. All values collected in dataframe ydf.
d. Now dataframes xdf and ydf are fitted into the linear regression model.
e. For prediction, we create another dataframe of 2 columns of z’s. Each column having
alternate CK row’s sum. Sum of each column is taken. This gives two values that shall be
used in predicting through our linear regression model.
f. On prediction another 2 values are generated, we take mod 26 of them and store as x
and y.
g. Now for each character in cipher text we find ascii value then substract x and add y.
Then convert the gotten value back to character and append to a string.
h. The result string is our final cipher text.
10. We now decrypt the cipher text further using hashed key by AES-256.
11. We change the encoding of this decrypted data to utf-8 and save it as PNG file to get the original
image.
Output: original image in PNG.

Instructions to the code


1. .zip file is to be unzipped.
2. Juypter Notebook is to be run and navigated to the folder from the zip file.
3. Run [Link] file to convert an image from pics folder to cipher text.
4. [Link] in keys folder is used in encryption.
5. ToBeSent for Decryption folder stores the generated cipher text and key split images.
6. On running the [Link] file we get our original image named as DecryptedImg.

Note: For another run some file names and folder names have been changed in the code.

Common questions

Powered by AI

The linear regression model in the two-layer Caesar cipher is used to process the encryption and decryption layers by predicting values to modify the cipher text. During encryption, X values from model are chosen based on the sum of alternate row elements in image P, and Y values based on R. This results in predictions which, after a mod 26 operation, are used to adjust ASCII values of the cipher text. In decryption, the same model predicts transformations needed to retrieve original ASCII values, consistent with transforming alternate rows' sums in images P and R .

The dual-layer encryption approach first encrypts the image string using AES-256 with a SHA-256 hashed key to form a basic cipher text. Then, the two-layer Caesar cipher employs a linear regression model on the alternate row sums of images P and R to adjust ASCII values further, providing an additional layer of obfuscation. This combination benefits from AES's robustness in encrypting data and the linear regression-enabled Caesar cipher's complexity, enhancing difficulty for potential cryptanalysis, therefore increasing security .

The project combines AES encryption with visual cryptography by using AES-256 for encrypting the image string into cipher text with a hashed key. This key is then converted into an image, which is split into two images, P and R. C is another image initialized and filled by comparing the ASCII values of the key characters. P is generated from an XOR operation between R and C. This results in two images, P and R, that help in further encryption processes and illustrate visual cryptography through the secure distribution of key content across multiple layers .

After initial AES-256 encryption, the final cipher text undergoes transformation via a two-layer Caesar cipher. This involves adjusting ASCII values of the cipher text based on predictions from a linear regression model, which uses alternate row sums from P and R. Each cipher text character's ASCII value is moderatively altered by these predictions, bolstering security by adding complexity and effectively obfuscating the encoded content further from simple linear AES encryption, thus enhancing resistance against deciphering .

SHA-256 is used to hash the key (K) before it's used for AES encryption, ensuring that the key utilized in encryption is of a fixed length and adding a layer of security since hashed keys are difficult to reverse-engineer. This hashing converts the key into a form suitable for producing strong encryption while protecting the original key and making sure its complex structure is uniformly distributed .

The process involves converting the original encryption key into an image where each row corresponds to the ASCII code of a character in the key. This image is then split into two visual components, images P and R, using an XOR technique with random values in R. This splitting into P and R ensures that even if one image is exposed, the original key remains secure. This technique, part of visual cryptography, enhances security by distributing the key content across two secured images which individually convey no meaningful information about the original key .

Randomization in image R, achieved by assigning each pixel a random value between 0 and 1, is crucial to the encryption as it ensures that image P, formed by XORing R with the deterministic image C, is unpredictable. This randomness shields the encryption process from deterministic patterns that could be exploited by attackers to infer key information, thus preventing reverse-engineering of key components. Randomization enhances the uniqueness of each encryption instance, making attacks like brute force or differential cryptanalysis impractical .

Challenges include compatibility and coordination among libraries used (e.g., base64, hashlib, Crypto, numpy, cv2, sklearn) for various stages of encryption and decryption. Ensuring precise conversion between data formats and handling potential execution errors are crucial, especially when harmonizing processes like image manipulation and model training. The project mitigates these challenges by integrating these libraries in a Python Jupyter Notebook environment, which allows interactive execution and debugging, aiding in maintaining seamless integration of visual cryptography with AES and Caesar cipher models .

In the decryption process, visual cryptography facilitates the reconstruction of the original key by using images R and P to create a new image CK. This image CK, derived from XOR'ing P and R at each pixel position, is used to count the number of black pixels per row, corresponding to ASCII values, to regenerate the original encryption key used. Therefore, despite the destruction of the original key, enough visual cues remain in P and R for reconstitution in the decryption phase .

During decryption, once the key is reconstructed from images P and R and the two-layer Caesar cipher is reversed using the linear regression model to yield the initial AES cipher text, this initial text is decrypted using AES-256 with the hashed key. Subsequently, decoding the decrypted data back into utf-8 format allows the binary information to be saved as the original PNG image, completing the precise reverse-engineering of the initial encryption .

You might also like