Algorithm 4: ElGamal with Double Playfair Cipher |
Input: The image of size 256 × 256 to be encrypted or decrypted. |
The key matrices corresponding to Double Playfair Cipher. |
The ElGamal cryptosystem parameters. |
Output: The corresponding cipher image or original image of size 256 × 256. |
1. Key Generation for Double Playfair Cipher |
(a) A modified key space of 2 matrices, each of size 16 × 16 is used instead of standard |
5 × 5 key matrices used in Double Playfair cipher. |
(d) Create 2 key maps, 1 corresponding to each of the keys. The key maps have pixel |
intensities as keys and their location in the respective key matrix as the |
corresponding value (represented by a tuple of row and column). |
2. Key Generation for ElGamal Cryptosystem |
(a) Receiver chooses a prime number p and computes its generator
|
(b) Publish the public key, prime number p, and generator g. |
(c) Sender chooses a random integer i in the range: . |
(d) Sender computes the temporary key or ephemeral key as:
|
(e) The masking key is computed by sender as: . |
3. Encryption process |
(a) Read the image to be encrypted and separate it to different channels as R, G, B. |
Pair up pixels in 2 for each of the channels separately. |
(b) To apply Vertical Double Playfair Cipher find the location of first value from pixel |
pair from the first key map and the location of second pixel value from the second |
key map. Then if the pixels are in same column keep them unchanged, else find the |
pixel intensities at the opposite corners of the rectangle formed by the pair of input |
pixels considered. Place them in the same order as they correspond to the order of |
pixel values in the input pair. |
(c) Substitute the cipher pixel values to create the cipher image of size identical to that |
of the input image. |
(d) Encrypt each of the key matrices using the masking key from ElGamal Encryption as: |
|
where denotes the corresponding pixel intensity in a cell of a key matrix. |
(e) Send the encrypted image and encrypted key matrices along with ElGamal public key |
(ephemeral key) of sender to the receiver. |
4. Decryption process |
(a) The masking key will be computed by receiver as: . |
(b) The key matrices for Double Playfair Cipher are decrypted as: |
. |
(c) Read the image to be decrypted and separate it to different channels as R, G, B. |
Pair up pixels in 2 for each of the channels separately. |
(d) To apply Vertical Double Playfair Cipher find the location of first value from pixel |
pair from the first key map and the location of second pixel value from the second |
key map. Then if the pixels are in same column, keep them unchanged. |
Otherwise, find the pixel intensities at the opposite corners of the rectangle |
formed by the pair of input pixels considered. Place them in the same order as they |
correspond to the order of pixel values in the input pair. |
(e) Substitute the decrypted pixel values to create the original image. |