# A Lightweight Image Cryptosystem for Cloud-Assisted Internet of Things
## 3 Materials and Methods
### Proposed Lightweight Image Cryptography Algorithm
FOR I = 0 TO \(\frac{n}{2}-1\)
5. \(xorbit[i]=L[i]\otimes R[i]\)
6. \(xorbitR=CONCATENATE(xorbit,R)\)
7.  enclock = CONVERT enchits to pixels
8. STOP
```  
**Algorithm 1**Encryption module (block, permkey)  
Figure 1(b) depicts the encryption process where the encryption module of HXP is used. The image to be encrypted, pinnage, and the encryption key, K, are the two inputs for the encryption process. The encryption process involves random key generation, random image generation, and generation of cipher images, which are detailed as follows:  
1. Random key generation: An array of random integer, PERMkey, is generated using the key. Given an image A with dimension \((a\times b\times c)\), the image A is converted into a grayscale image, grayA, of dimension \((a\times b)\). If a > b, the size of PERMkey will be a; otherwise, the size of PERMkey will be b. 2. Random image generation: the bytes of grayA and that of the key are combined together to form Cbyte. Cbyte is made to pass through SHA\(-256\). The first k bits of the output of SHA\(-256\), where k is the block size, is selected as the shavalue. The shavalue is encrypted using the encryption module and the output is used as the seed to generate the pixels of a random image, Random image. The size of Random image is equal to the size of grayA. A bitwise XOR operation is carried out between Randomimage and grayA to form interimage. 3. Cipher image generation: The generation of cipherimage is carried according to Equations (6) and (7), where nrows and ncols represent the quantity of rows and columns in the interimage, respectively. Equations (6) and (7) outline the description of how the bits of interimage are manipulated along the rows and columns of the image, respectively, to form an encrypted image. \[ \begin{array}{l}cipherimage[row,:]\\ =Encryptionmodule(interimage[row,:],\ PERMkey[row]\ )for\ 0\leq row\\ <nrows\end{array} \] (6) \[ \begin{array}{l}cipherimage[:,col]\\ =Encryptionmodule(cipherimage[:,col],\ PERMkey[col]\ )for\ 0\leq col\\ <ncols\end{array} \] (7) The pseudocode in Algorithm 3 represents the design of the encryption process in HXP. ```
Output:encimage
1.START
2.grayA = CONVERT pimage to gray image of dimension h and w
3.cbyte = CONCATENATE (grayA, K)
4.randseed = CALL generaterandomseed(key) // Algorithm 7
5.blocksize = MAXIMUM (h, w)
6.permkey [1...blocksize] = GENERATE array of random integers using randseed as seed
7.hashvalue = HASH (cbyte)
8.hashvalue = hashvalue [1...blocksize]
9.enchashvalue = CALL EncryptionModule(hashvalue,permkey) // Algorithm 1
10.resed = CALL generaterandomseed(enchashvalue) // Algorithm 7
11.randomize = Generate random image of size (h \(\times\) w) using rseed as seed
12.interimage = XOR (randomize, grayA)
13.FOR i = 0 TO h - 1
14.FOR j = 0 TO w - 1
15.STOP
```  
**Algorithm 3**Encryption process (pimage, K)  
The decryption procedure converses the steps in the encryption procedure to recover the plain image from the cipher image. Algorithms 4 and 5 outline the design of the decryption module and the decryption process in HYP, respectively.