# A Lightweight Image Cryptosystem for Cloud-Assisted Internet of Things
## 3 Materials and Methods
### Proposed Lightweight Image Cryptography Algorithm
A cryptosystem with a lower value of the MD between the plain image and the decrypted image is said to be better, as a lower value indicates that there is no substantial alteration between the two images. The formula for finding the MD is outlined by Equation (15). \[MD=MAX(P(i,j)-C(i,j))\] (15)
* Average difference (AD): A higher value of the AD, that can be obtained when the plain image P and the cipher image C are used for the computation, signifies that the image cryptosystem is secure, while a low value implies a less secure cryptosystem. In the case of the computation of the AD between P and the decrypted image D, which can be obtained when C undergoes the decryption process, a lower value of AD implies a better quality of the decrypted image, while a high value indicates that the decryption process cannot obtain an image that is similar to P from C. Equation (16) represents the formula for determining the AD between the two images P and C, where \(P(i,j)\) and \(C(i,j)\) represent the pixels at grid location (i,j) of P and C, respectively. \[AD=\frac{1}{MN}\sum_{i=1}^{M}\sum_{j=1}^{N}(P(i,j)-C(i,j))\] (16)
* Structural content (SC): SC is another metric that can be used to measure the image quality. The image quality of a processed image, Pm, is a measure of the degradation of pm when compared to an ideal image, P. Achieving a value of 1 for the SC indicates a high quality of Pm, while a higher value indicates a low quality of Pm. For a good cryptosystem, when the cipher image Pm is compared with the original image P,it is expected that the value of SC should be high for the cipher to be regarded as secure. When the decrypted image D is compared to P, it is expected that a good cryptosystem should provide a SC of 1 in order for the cipher to be rated as being able to retrieve the exact copy of P from the cipher image Pm. Equation (17) represents the formula for calculating the SC between the original image P and the processed image (cipher/decrypted) Pm. \[SC=\frac{\sum_{i,j}^{M,N}\left(P_{i,j}\right)^{2}}{\sum_{i,j}^{M,N}\left(Pm_{ i,j}\right)^{2}}\] (17)
4. Two-dimensional correlation coefficient (2 DCC): The 2 DCC can be used to calculate the similarity or difference between two images. If the value of the 2 DCC is small (or zero), the two images are said to be different. A large value of the 2 DCC implies that the two images are similar. Equation (18) represents the formular for finding the 2 DCC between two images P and C. \[MSE=\frac{1}{MN}\sum_{i=1}^{M}\sum_{j=1}^{N}(P(i,j)-C(i,j))^{2}\]0 (18)

where \(P_{i,j}\), \(C_{i,j}\), \(\mu_{p}\), and \(\mu_{c}\) are the pixels at grid location (i,j) of P and C, and the averages of the pixels in P and C, respectively. 5. Differential cryptanalysis: The net pixel change rate (NPCR) [51] and the unified average change intensity (UACI) [52] are the commonly used metrics for measuring the resistance of a cipher to cryptanalysis attack between two images P and C. The ideal values of the NPCR and UACI, according to the authors of [53], are 99.6093% and 33.4635%, respectively, for the differential cryptanalysis-resistant cipher. The formulae for determining the NPCR and UACI are given in Equations (19) and (20), respectively: \[MSE=\frac{1}{MN}\sum_{i=1}^{M}\sum_{j=1}^{N}(P(i,j)-C(i,j))^{2}\]1 (19) \[MSE=\frac{1}{MN}\sum_{i=1}^{M}\sum_{j=1}^{N}(P(i,j)-C(i,j))^{2}\]2 (20) where D(i,j) = 0 if \(P(i,j)=C(i,j)\); otherwise, \(D(i,j)=1\) and \(E(i,j)=abs(P(i,j)-C(i,j)\). 6. Histograms are graphical representations of the distribution of gray levels in the pixels of images [54]. Ciphertext images always have a uniform distribution of pixels; in the case of a plaintext image, these pixels are jerky. A uniform histogram of a cipher image therefore indicates a secure encryption scheme [55]. A Chi-square test was carried out to validate the histogram's uniformity.