# 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"](https://www.hindawi.com/journals/jece/2012/173931/) 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<sup>α </sup>-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
- Python3 ( https://www.python.org/downloads/ )
- Python3 package dependencies - Run `pip3 install -r requirements.txt`
## 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]
```
2. 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 -

Raw data
{
"_id": null,
"home_page": "https://github.com/dannyi96/Image-Cryptography",
"name": "rubikencryptor",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Daniel Isaac",
"author_email": "danielbcbs2@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4c/ad/7a337147c39ebba6162576f2b379d5bd93007d4def2f4c9cf36e221d0c39/rubikencryptor-1.0.10.tar.gz",
"platform": null,
"description": "# Image Cryptography Based on Rubix's Cube Principle\n\nImplementation 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\"](https://www.hindawi.com/journals/jece/2012/173931/) by Khaled Loukhaoukha, Jean-Yves Chouinard and Abdellah Berdai.\n\n## Algorithm Overview\n\nGiven an input image having the three R,G,B matrices of size `M X N`\nHyperparameters include \n`\u03b1` - used for vector creation\n`ITER_MAX` - maximum number of times to carry out operations\n\n#### A. Encyption\n1. Create two vectors `Kr` and `Kc` with `|Kr|=M` & `|Kc|=N`. The values of these vectors are randomly picked from 0 to 2<sup>\u03b1 </sup>-1\n2. Repeat below steps `ITER_MAX` number of times\n\n i. **Rolling Rows:** \n \n * The sum of all pixel values of every row of the image RGB matrices are calculated one by one. \n \n * If the sum of a given row `rowNumber` is even, Roll the row to the right `Kr[rowNumber]` times \n Otherwise roll to the left `Kr[rowNumber]` times.\n\n ii. **Rolling Columns:**\n \n * The sum of all pixel values of every column of the image RGB matrices are calculated one by one. \n \n * If the sum of a given row `columnNumber` is even, roll the column up `Kc[columnNumber]` times.\n Otherwise roll the column down `Kc[columnNumber]` times.\n\n iii. **XORing Pixels:**\n \n * For every pixel(i,j), XOR the pixel with the below two values\n \n - Value #1 - `Kc[columnNumber]` if `i` is odd else 180 rotated bit version of `Kc[columnNumber]`\n \n - Value #2 - `Kr[rowNumber]` if `j` is even else 180 rotated bit version of `Kr[rowNumber]`\n\n\n#### B. Decryption\n Given an encrypted image, vectors `Kr` and `Kc` & `ITER_MAX` , decryption can be done by following the reverse procedure - XORing pixels \u2192 Rolling Columns \u2192 Rolling Rows `ITER_MAX` number of times\n\n## Prerequisites\n\n- Python3 ( https://www.python.org/downloads/ )\n\n- Python3 package dependencies - Run `pip3 install -r requirements.txt`\n\n## Running \n\n\n1. Using the crypto_client.py script supplying neccessary parameters\n```\n$ python3 crypto_client.py -h\nusage: crypto_client.py [-h] [--type TYPE] [--image IMAGE] \n [--alpha ALPHA] [--iter_max ITER_MAX] \n [--key KEY] [--output_image OUTPUT_IMAGE]\n```\n\n2. Using rubikencryptor python package\n```\nfrom rubikencryptor.rubikencryptor import RubikCubeCrypto\nfrom PIL import Image\n\n# Encrypt image\ninput_image = Image.open('image1.png')\nencryptor = RubikCubeCrypto(input_image)\nencrypted_image = encryptor.encrypt(alpha=8, iter_max=10, key_filename='key.txt')\nencrypted_image.save('encrypted_image.png')\n\n# Decrypt image\ndecryptor = RubikCubeCrypto(encrypted_image)\ndecrypted_image = decryptor.decrypt(key_filename='key.txt')\ndecrypted_image.save('decrypted_image.png')\n```\n\n## Example -\n\nOriginal Image\n\n\n\nRun Encryption on the Original Image\n```\n$ python3 crypto_client.py --type encrypt\n --image example/original.png \n --output_image example/encrypted.png \n --key example/encoded_key.txt \n --alpha 8 --iter_max 10\n```\n\nencrypted image is stored at `example/encrypted.png` & key is stored at `example/encoded_key.txt `\n\nEncrypted Image\n\n\n\nRun Decryption on the Encryped Image using the Key\n\n```\n$ python3 crypto_client.py --type decrypt \n --image example/encrypted.png \n --output_image example/decrypted.png \n --key example/encoded_key.txt\n```\n\ndecrypted image is stored at `example/decrypted.png` \n\nDecrypted Image -\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Image Cryptography Based on Rubix's Cube Principle",
"version": "1.0.10",
"project_urls": {
"Homepage": "https://github.com/dannyi96/Image-Cryptography"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4603f744c7a237771d693c8c571da9e4a57aaf2d03d5e83a0a55bdb594593880",
"md5": "2d10c98d6588ff5cfb48aec5fa2cd09d",
"sha256": "70c53473da89ec5393b59e4ea1d6b571e89075e06310cc000f403102e018bb25"
},
"downloads": -1,
"filename": "rubikencryptor-1.0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2d10c98d6588ff5cfb48aec5fa2cd09d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4715,
"upload_time": "2023-11-18T14:09:25",
"upload_time_iso_8601": "2023-11-18T14:09:25.627941Z",
"url": "https://files.pythonhosted.org/packages/46/03/f744c7a237771d693c8c571da9e4a57aaf2d03d5e83a0a55bdb594593880/rubikencryptor-1.0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4cad7a337147c39ebba6162576f2b379d5bd93007d4def2f4c9cf36e221d0c39",
"md5": "cad92df4390a05cc548ba4d719b06f2f",
"sha256": "5c9c01c4885e3f19f1a32d6be07060836ad7a5ae5e274c70ead2fe2bf8016c37"
},
"downloads": -1,
"filename": "rubikencryptor-1.0.10.tar.gz",
"has_sig": false,
"md5_digest": "cad92df4390a05cc548ba4d719b06f2f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4444,
"upload_time": "2023-11-18T14:09:28",
"upload_time_iso_8601": "2023-11-18T14:09:28.190763Z",
"url": "https://files.pythonhosted.org/packages/4c/ad/7a337147c39ebba6162576f2b379d5bd93007d4def2f4c9cf36e221d0c39/rubikencryptor-1.0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-18 14:09:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dannyi96",
"github_project": "Image-Cryptography",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "numpy",
"specs": [
[
"==",
"1.20.2"
]
]
},
{
"name": "Pillow",
"specs": [
[
"==",
"8.4.0"
]
]
}
],
"lcname": "rubikencryptor"
}