# A Lightweight Image Cryptosystem for Cloud-Assisted Internet of Things
## 3 Materials and Methods
### Proposed Lightweight Image Cryptography Algorithm
The SSIM between images P and C can be found by applying the formula in Equation (11), where \(D_{1}\) and \(D_{2}\) are constant to steady division with the feeble denominator. \[SSIM(P,C)=\frac{\left(2\mu_{p}\mu_{c}+D_{1}\right)\left(2\sigma_{pc}+D_{2} \right)}{\left(\mu_{p}{}^{2}+\mu_{c}{}^{2}+D_{1}\right)\left(\sigma_{p}{}^{2} +\sigma_{c}{}^{2}+D_{2}\right)}\] (11)

For a secure cryptosystem with good decryption quality, the SSIM between the plain image P and the cipher image C is expected to be low and close to \(-1\); meanwhile, the SSIM between P and the decrypted image Di is expected to high and close to \(1\). 5. Normalized cross-correlation (NCC): NCC is a widely accepted metric for measuring similarity between the two images P and C. The value of NCC ranges from \(-1\) to \(1\). The value \(-1\) implies that there is strong correlation between P and C, while the value \(1\) indicates that there is no strong correlation between P and C. NCC is also used in measuring image quality in image processing. Pixels of plain image P and that of the cipher image C should lack a correlation. Hence, it is expected that the NCC between P and C should be close to \(1\) for a good cipher. There should be a strong correlation between the pixels of P and that of the decrypted image D obtained from the decryption of C. Hence, the NCC value obtained when P and D are used as the inputs should be close to \(-1\). Equation (12) details the mathematical description of NCC:

\[NCC=\frac{1}{M\times N}\times\frac{\sum_{i,j}^{M,N}\left(P_{i,j}-\mu_{p} \right)\times\left(C_{i,j}-\mu_{c}\right)}{\sqrt{var_{P}\times var_{C}}} \tag{12}\]

where M and N represent the height and width of the images P and C (the two images should have the same size), \(P_{i,j}\) represents the pixel of image P at row i, column j, \(\mu_{p}\) and \(\mu_{c}\) represent the mean of the pixels in images P and C, respectively, and \(var_{P}\)_and_\(var_{C}\) represent the variance of images P and C, respectively. * Mean absolute error (MAE): The MAE can be used in the determination of an image's quality and the resistance of an image cryptosystem to differential attacks. An image cryptosystem is considered secure if the value of MAE is greater than 75; otherwise, the cryptosystem is said to be insecure. When comparing cryptosystems, a cryptosystem that has a higher value of MAE is said to be more secure. When considering the quality of the plain image and decrypted image obtained from the decryption of the cipher image, a cryptosystem that has the lower value of MAE is said to produce a higher quality image than the one with a higher value of MAE. Equation (13) represents the formula for determining the MAE of a cryptosystem: \[MAE=\frac{1}{MN}\sum_{i=1}^{M}\sum_{j=1}^{N}\lvert P(i,j)-C(i,j)\rvert\] (13) where \(P(i,j)\), and \(C(i,j)\) are the pixels in P and C at grid location \((i,j)\), respectively. * Normalized absolute error (NAE): NAE is a metric that can be used to compare the quality of an image with that of a reference image. If the value of NAE is high, it means that the image quality is low. A low value of NAE implies a higher quality of the image. Equation (14) represents the formula for calculating the NAE between the reference image P and image C. \[\frac{\sum_{i,j=1}^{M,N}(\lvert P(i,j)-C(i,j)\rvert)}{\sum_{i,j=1}^{M,N}P(i,j)}\] (14)
* Maximum difference (MD): The MD is determined by obtaining the maximum value when corresponding pixels at grid location (i,j) of plain image P and the cipher image C are subtracted from each other, as shown in Equation (15). A higher value of the MD indicates a significant difference between P and C. Hence, a cryptosystem with a higher value of MD is said to be more secure than the one with a lower value. In the case of consideration of P and the decrypted image D obtained from the decryption of C, a lower value of the MD is desirable.