Image-Cryptography
Image-Cryptography copied to clipboard
Implementation of image cryptography using Rubik's Cube Principle https://www.hindawi.com/journals/jece/2012/173931/
Image Cryptography Based on Rubix's Cube Principle
Implementation of image encryption and decryption using Rubix's Cube Principle. This algorithm is based on the paper "A Secure Image Encryption Algorithm Based on Rubik's Cube Principle" by Khaled Loukhaoukha, Jean-Yves Chouinard and Abdellah Berdai.
Algorithm Overview
Given an input image having the three R,G,B matrices of size M X N
Hyperparameters include
α - used for vector creation
ITER_MAX - maximum number of times to carry out operations
A. Encyption
-
Create two vectors
KrandKcwith|Kr|=M&|Kc|=N. The values of these vectors are randomly picked from 0 to 2α -1 -
Repeat below steps
ITER_MAXnumber of timesi. Rolling Rows:
-
The sum of all pixel values of every row of the image RGB matrices are calculated one by one.
-
If the sum of a given row
rowNumberis even, Roll the row to the rightKr[rowNumber]times Otherwise roll to the leftKr[rowNumber]times.
ii. Rolling Columns:
-
The sum of all pixel values of every column of the image RGB matrices are calculated one by one.
-
If the sum of a given row
columnNumberis even, roll the column upKc[columnNumber]times. Otherwise roll the column downKc[columnNumber]times.
iii. XORing Pixels:
-
For every pixel(i,j), XOR the pixel with the below two values
-
Value #1 -
Kc[columnNumber]ifiis odd else 180 rotated bit version ofKc[columnNumber] -
Value #2 -
Kr[rowNumber]ifjis even else 180 rotated bit version ofKr[rowNumber]
-
-
B. Decryption
Given an encrypted image, vectors Kr and Kc & ITER_MAX , decryption can be done by following the reverse procedure - XORing pixels → Rolling Columns → Rolling Rows ITER_MAX number of times
Prerequisites
-
Python3 ( https://www.python.org/downloads/ )
-
rubikencryptor package - Run
pip3 install rubikencryptor
Running
- Using the crypto_client.py script supplying neccessary parameters
$ python3 crypto_client.py -h
usage: crypto_client.py [-h] [--type TYPE] [--image IMAGE]
[--alpha ALPHA] [--iter_max ITER_MAX]
[--key KEY] [--output_image OUTPUT_IMAGE]
- Using rubikencryptor python package
from rubikencryptor.rubikencryptor import RubikCubeCrypto
from PIL import Image
# Encrypt image
input_image = Image.open('image1.png')
encryptor = RubikCubeCrypto(input_image)
encrypted_image = encryptor.encrypt(alpha=8, iter_max=10, key_filename='key.txt')
encrypted_image.save('encrypted_image.png')
# Decrypt image
decryptor = RubikCubeCrypto(encrypted_image)
decrypted_image = decryptor.decrypt(key_filename='key.txt')
decrypted_image.save('decrypted_image.png')
Example
Original Image -

Run Encryption on the Original Image
$ python3 crypto_client.py --type encrypt
--image example/original.png
--output_image example/encrypted.png
--key example/encoded_key.txt
--alpha 8 --iter_max 10
encrypted image is stored at example/encrypted.png & key is stored at example/encoded_key.txt
Encrypted Image -

Run Decryption on the Encryped Image using the Key
$ python3 crypto_client.py --type decrypt
--image example/encrypted.png
--output_image example/decrypted.png
--key example/encoded_key.txt
decrypted image is stored at example/decrypted.png
Decrypted Image -

Demo using a Web App ( Early beta version )
Note - this is still in early beta version. Performance enhancements, bug fixes & improved styling are expected.
App hosted at https://dannyi96.github.io/Image-Cryptography/
https://github.com/dannyi96/Image-Cryptography/assets/15380498/da99a862-fa52-46eb-9ff2-306e8d504da0
Future of project
Refer the proposed Roadmap
Main goals include
- Improving the Web App demonstrating this package
- Measuring the current performance of the package ( encryption & decryption )
- Improving the performance of the package ( encryption & decryption )
- Improving Quality via Testcases, Linters, CICD pipeline
- (Stretch goal) Including technical aspects of the research paper as to why the algo is resistant to various attacks as part of the WebApp