# A Lightweight Image Cryptosystem for Cloud-Assisted Internet of Things
## 3 Materials and Methods
### Proposed Lightweight Image Cryptography Algorithm
The formula for calculating the uniformity of histograms is given by Equation (21): \[MSE=\frac{1}{MN}\sum_{i=1}^{M}\sum_{j=1}^{N}(P(i,j)-C(i,j))^{2}\]3 (21) where i is the pixel value in the interval (0...255), \(O_{i}\) is the observed frequency of each i, and for a grayscale image with height M and width N, the expected frequency \(E=\frac{M\times N}{256}\). The significance level \(\propto\) was set to 0.05. A Chi-square test was carried out and the \(p\)-value was obtained. If the \(p\)-value \(<=\propto\), the histogram is not uniform. If the \(p\) value \(>\propto\), then the histogram is uniform. 7. Adjacent pixels correlation coefficient: The correlation coefficient of adjacent pixels in an image can be calculated by applying Equation (22) [56]: \[MSE=\frac{1}{MN}\sum_{i=1}^{M}\sum_{j=1}^{N}(P(i,j)-C(i,j))^{2}\]4 (22) where \(E\) is the pixel value in the interval (0...255), \(O_{i}\) is the observed frequency of each i, and \(E\) is the observed frequency of each \[\left\{ \begin{array}{l}\text{E(x)}=\frac{1}{n}\sum\limits_{i=1}^{n}x_{i},\quad \text{D(x)}=\frac{1}{n}\sum\limits_{i=1}^{n}\left(x_{i}-\text{E(x)}\right)^{2} \\ \gamma_{x,y}=\frac{\text{cov(x,y)}}{\left(\sqrt{\text{D(x)}}\right)\left(\sqrt{ \text{D(y)}}\right)},\text{D(x)}\
eq 0\text{ and D(y)}\
eq 0\\ \text{cov(x,y)}=\frac{1}{n}\sum\limits_{i=1}^{n}\left(x_{i}-\text{E(x)}\right) \left(y_{i}-\text{E(y)}\right)\end{array} \right. \tag{22}\]

where \(x_{i}\) is the grayscale value of a pixel, \(n\) is the number of pairs \((x_{i},y_{i})\), and E(x) and E(y) are the mean values of \(x_{i}\) and \(y_{i}\), respectively. It is expected that the results of an adjacent pixel correlation coefficient of a good encryption scheme should be close to zero [50]. * The statistical measure that was used to test the entropy of the proposed image cryptosystem is given by the formula in Equation (23): \[H(m)=\sum\limits_{i=0}^{2^{N}-1}P(m_{i})\text{log}_{2}\left(\frac{1}{P(m_{i})}\right)\] (23) where m represents the image, \(2^{N}\) represents the pixel sample space, \(m_{i}\) represents the pixel i of image m, and \(P(m_{i})\) represents the probability of \(m_{i}\). The entropy H(m) of an image, encrypted with a \(2^{N}\) pixel sample space, is N. The pixel space was 256; hence, \(2^{N}=256=2^{8}\). The maximum value of N was 8. In order for an image cryptosystem to be rated as resistant to an entropy attack, the result of the entropy analysis of the encrypted image should be close to 8. A cryptosystem that has an information entropy H(m) very close to 8 is said to be resistant to an entropy attack. #### 3.2.2 Methods of Analysis

In this section, the details of the analysis carried out on the proposed lightweight image cryptosystem are discussed. The following analyses were carried out: simulation, system sensitivity, statistical, and required resources analyses. * Procedure for simulation analysis: 'airplane.tiff','baboon.tiff','boat.tiff','lena.tiff', and 'pepper.tiff' were retrieved from the USC-SIPI image database ([[http://sipi.usc.edu/database/](http://sipi.usc.edu/database/)]([http://sipi.usc.edu/database/](http://sipi.usc.edu/database/))) for simulation purposes. Each of the images was converted into a grayscale image. Each of the grayscale images was made to pass through an encryption algorithm of the proposed image cryptosystem to obtain a cipher image. Each of the obtained cipher images was also made to pass through the decryption algorithm of the proposed image cryptosystem to ascertain whether or not the decryption process is able to recover the original image from the cipher image. * Procedure for encryption/decryption quality analysis: In order to justify the claim as per the quality of the images produced by the encryption and decryption processes and the security of the proposed cryptosystem, metrics 1-10 were used. For EQ, the images produced by the encryption process were compared with the original images. For DQ, the images produced by the decryption process were compared with the original images.