# Image encryption using cellular automata

To propose an image encryption system using one dimensional cellular automata for image encryption and decryption. Cellular automata can be corresponded with the essential cryptographic properties i.e. Balance, correlation-immune, nonlinearity, easy to implement in hardware. CA cryptosystems can give better performances compared to classic methods that are based on computational techniques. Therefore, this technique should be most favourable for cryptography.

**Features:**

**1. Encryption –**

**RGB:**Extract individual RGB channel to encrypt each layer and merge.**Gray:**Convert the given image to grayscale and use it for encryption.

**2. Decryption –**

**Key:**Use a key for each pixel for decryption process stored in a separate file.**Preset:**Use predefined rules to decrypt the image.

**3. Result and Analysis –**

**Histogram:**Histogram analysis is defined as the frequency of the image pixels in graphical representation.**Correlation:**Correlation is a statistical measure that indicates the extent to which two or more variables fluctuate together.

**4. Rule Selection –**

Rules to be applied to to encrypt image can be selected and order can be changed (R30, R90, R120).Further rules can also be added.

**Implementation/Algorithms:**

**Encryption –**

Converting image to 2d matrix and modifying each pixel value by using key function.- Grayscale image is taken as input.
- Image is converted to a 2D matrix (M).
- Execute M1=Key (M), where M1 is the encrypted 2D matrix.
- Each pixel values of M matrix is modified by using the Key function h1(M) depending on whether the value of the pixel sent is odd or even which is stored in a separate index file INF for each pixel.
- The modified pixel is then received and stored in M1.
- Matrix M1 is converted to image and saved as an encrypted image.

**Decryption –**

Original pixels are retrieved by using the reverse technique- Encrypted image is taken as an input
- Image is converted to a 2D matrix(M1).
- M=Key(M1) is executed, where M is the decrypted 2D matrix.
- Each pixel values of M1 matrix is modified by using the Key function h1(M) using its corresponding odd/even rule from index file INF.
- The modified pixel is then received and stored in M1.
- The M matrix is converted to image and saved as decrypted image.

**Key Function –**

Here a 2D matrix is taken as an input and this key () function is called during encryption as well as decryption which modifies the input pixel value using cellular automata rule vector.- The input pixel is converted into binary number of 8 blocks.
- Distinct cellular automata rules are applied per block.
- If input value is even, rule 90 and 30 are applied alternatively.
- If input value is odd, rule 90 is applied.
- The rule configuration is run till the initial input block repeats itself.
- Recursion stage is noted and half of that cycle is calculated hc = n/2.
- The rules are run once again but this time for half the cycle (hc).
- Final output of the array is converted back to decimal number and placed in the encrypted /decrypted value of the input block.
- Step 1 to step 7 is repeated until all the grayscale values are encrypted /decrypted.

**Tools:**

This image encryption system has been prepared on Python and MATLAB.

Following libraries are used:

OpenCV:To extract image pixels and modify it.Numpy:To make use of arrays in key function.Matplotlib:To obtain results (histogram, correlation)

Following Cellular Automata rules have been applied:

Rule 90 Rule 30 Rule 120

The whole program is divided into modules:

Encryption Script Decryption Script Result and Analysis

**Application –**

Image encryption is the primary task of the program I developed although the system proposed is not only limited to Image encryption. The system can be modified to achieve:

- Coding messages
- Picture compression
- Production of pseudo-random numbers.

**Project Link:**

https://github.com/Lakshyasukhralia/CellularAutomata

## Recommended Posts:

- Cellular Networks
- Handoff in Cellular Telecommunications
- Public Key Encryption
- RC5 Encryption Algorithm
- RC4 Encryption Algorithm
- ElGamal Encryption Algorithm
- Data encryption standard (DES) | Set 1
- Difference between Encryption and Decryption
- Encryption, Its Algorithms And Its Future
- End to End Encryption (E2EE) in Computer Networks
- Rail Fence Cipher - Encryption and Decryption
- Image Steganography in Cryptography
- Backing up Cisco IOS Router image
- Channel Allocation Strategies in Computer Network

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.