Skip to main content

Image Cryptography Based on Rubix's Cube Principle

Project description

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

  1. Create two vectors Kr and Kc with |Kr|=M & |Kc|=N. The values of these vectors are randomly picked from 0 to 2α -1

  2. Repeat below steps ITER_MAX number of times

    i. 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 rowNumber is even, Roll the row to the right Kr[rowNumber] times Otherwise roll to the left Kr[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 columnNumber is even, roll the column up Kc[columnNumber] times. Otherwise roll the column down Kc[columnNumber] times.

    iii. XORing Pixels:

    • For every pixel(i,j), XOR the pixel with the below two values

      • Value #1 - Kc[columnNumber] if i is odd else 180 rotated bit version of Kc[columnNumber]

      • Value #2 - Kr[rowNumber] if j is even else 180 rotated bit version of Kr[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

Running

  1. 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]
  1. 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 -

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rubikencryptor-1.0.8.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

rubikencryptor-1.0.8-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file rubikencryptor-1.0.8.tar.gz.

File metadata

  • Download URL: rubikencryptor-1.0.8.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for rubikencryptor-1.0.8.tar.gz
Algorithm Hash digest
SHA256 c93a14d9ffdff99d0935fb94eab659eaaecece74f1a3218e574a37f0a820212f
MD5 f414b150d5cf1d5a14295cfbd7a44ac5
BLAKE2b-256 f7621ad4f287d5369dd7aca50946c4dd9de88959450cf1de70ba30372e361706

See more details on using hashes here.

File details

Details for the file rubikencryptor-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for rubikencryptor-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 726fc95d1bc6e82ec4defd7e73e715847c13286fe9c181188fb6420ca30975c1
MD5 133a87a7ac192fa6ed67daaa8f8594f3
BLAKE2b-256 2c35b9196c42ecd58249b19855824b968b7e5959234542902edc685855d69cd1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page