# A Lightweight Image Cryptosystem for Cloud-Assisted Internet of Things
## 3 Materials and Methods
### Proposed Lightweight Image Cryptography Algorithm
```
Output:decimage
1.START
2.h, w = SIZEOF(cimage)
3.resed = CALL generaterandomseed(key)//Algorithm 7
4.blocksize = MAXIMUM (h, w)
5.permkey [1...blocksize] = random integers obtained from using rseed as seed
6.hashvalue = hashvalue [1...blocksize]
7.enchashvalue = CALL EncryptionModule(hashvalue,permkey)//Algorithm 4
8.resed = CALL generaterandomseed(enchashvalue)//Algorithm 7
9.randomize = Generate random image of size (h x w) using rseed as seed
10.interimage = XOR (randomize, grayA)
11.FOR j = 0 TO w - 1
12.FOR i = 0 TO h - 1
13.STOP
```  
**Algorithm 14**Decryption procedure (cimage, hasvalue, key)  
``` Output:decimage
1.START
2.h, w = SIZEOF(cimage)
3.resed = CALL generaterandomseed(key)//Algorithm 7
4.blocksize = MAXIMUM (h, w)
5.permkey [1...blocksize] = random integers obtained from using rseed as seed
6.hashvalue = hashvalue [1...blocksize]
7.enchashvalue = CALL EncryptionModule(hashvalue,permkey)//Algorithm 4
8.resed = CALL generaterandom image of size (h x w) using rseed as seed
10.interimage = XOR (randomize, grayA)
11.FOR j = 0 TO w - 1
12.FOR i = 0 TO

### Metrics and Methods of Analysis of the Proposed Lightweight Image Cryptosystem

This section begins with the discussion of the metrics used for the analysis, following which the procedures for carrying out the analysis are outlined. #### 3.2.1 Metrics Used for the Analysis of the Proposed Algorithm

The security of the cryptosystem and the quality of the image obtained are very important features to look for in any image cryptosystem. The security of HXP and the quality of the decrypted images were measured using the following metrics:

1. Encryption quality (EQ): Given the plain image P and its equivalent cipher image C each with the equal size M \(\times\) N, the gray values of pixel P(I,j) and C(i,j) in P and C range from 0.. 255. If \(f_{L}(P)\) and \(f_{L}(C)\) represent the occurrence of each gray value, L, in P and C, respectively, then, Equation (8) gives the encryption quality of the cryptosystem. The higher the value of EQ, the better the \(\mid\)EQ of the cryptosystem. \[EQ=\sum_{L=0}^{255}\frac{\left(f_{L}(C)-f_{L}(P)\right)^{2}}{256}\] (8)
2. Mean square error (MSE): This metric measures the distance between the input P and the output C, where P and C represent the plain and cipher images of size MN, respectively. A cryptosystem with a high value of MSE indicates a better encryptionquality. Mathematically, the MSE of images P and C with pixels \(P(i,j)\) and \(C(i,j)\) at grid location \((i,j)\) is outlined by the formula in Equation (9). When the MSE is used as a metric for measuring the quality of the decrypted image, the image C in Equation (9) is replaced with the decrypted image D. In this scenario, the value of the MSE should be low for a good decryption algorithm. \[MSE=\frac{1}{MN}\sum_{i=1}^{M}\sum_{j=1}^{N}(P(i,j)-C(i,j))^{2}\] (9)
3. Peak signal-to-noise ratio (PSNR): The PSNR is a standard way of measuring image fidelity. It compares the quality of the cipher image C with that of the plain image P. Mathematically, PSNR is defined by Equation (10), where \(I_{max}\) represents the highest image pixel value. A secure cryptosystem is expected to produce low values of the PSNR; the low value indicates a great difference between P and C. In the case of comparing P and a decrypted image, the value of PSNR is expected to be infinity for a good cipher. \[PSNR=10\log_{2}\left(\frac{I^{2}_{max}}{MSE}\right)\] (10)
4. Structural similarity index measure (SSIM): SSIM values range from \(-1\) to \(+1\). A value of \(+1\) signifies a similarity between two images, whereas a value of \(-1\) implies a dissimilarity of the two images. The SSIM compares the two images based on their luminance, \(\mu_{p}\), which represents the average of all the pixel values. In contrast, \(\sigma_{p}\), which represents the standard deviation of all the pixel values, can be implemented to uncover the structural characteristics of the images, which are obtained by applying the following formula: \(\frac{P-\mu_{p}}{\sigma_{p}}\), where P is the input image.