# A New One-Dimensional Compound Chaotic System and Its Application in High-Speed Image Encryption
## 3 The Proposed Image Encryption Scheme
### The Encryption Process
#### 3.1.2. Row-by-Row Encryption Processing
```  
**Algorithm 3** A row-by-row encryption algorithm that combines scrambling and substitution. The detailed operational steps of the row encryption phase are described in Algorithm 3 below. ```
Input: Image matrix to be encrypted \(\mathbf{P}=\{P(i,j)\,|\,i=1,\,2,\,\ldots,\,M;\,j=1,\,2,\,\ldots,\,N\}\), \(x_{0},\,y_{0},\,a,\,b,\,C_{0}\) and \(N_{0}\). Output: Encrypted image matrix \(\mathbf{C}=\{C(i,j)\,|\,i=1,\,2,\,\ldots,\,M;\,j=1,\,2,\,\ldots,\,N\}\). ```  
**Algorithm 4** A row-by-row encryption algorithm that combines scrambling and substitution. **Step 1:** Call Algorithm 2 to generate four modified chaotic sequences: \(\mathbf{X}\), \(\mathbf{Y}\), \(\mathbf{I}\), \(\mathbf{J}\). Step 2:** Construct a row vector consisting of \(N\) identical constants \(C_{0}\): \(\mathbf{c}=[C_{0},\,C_{0},\,\ldots,\,]\), and pre-allocate the storage space of \(M\times N\) elements for the future encrypted image \(\mathbf{C}\). Step 3:** Get the initial row vector \(\mathbf{S}=k\times[S(1),\,S(2),\,\ldots,\,S(j),\,\ldots,\,S(N)]\) according to Equation (10), where \(S(j)\) is the sum of all pixel values in the \(j\)-th column in the image \(\mathbf{P}\). Step 4: Sequentially execute the operations described by Equation (13) to (16) for \(i=1,\,2,\,\ldots,\,M\), respectively, and complete the encryption of the \(i\)-th row:  
\[\mathbf{g}=\text{bitvor}(\mathbf{Y},\,\mathbf{c}). \tag{14}\]  
An intermediate key sequence \(\mathbf{g}\) is obtained from Equation (14), where \(\mathbf{g}=[g(1),\,g(2),\,\ldots,\,g(j),\,\ldots,\,g(N)]\). Executing Equation (14) is equivalent to performing the following operations for all \(j=1,\,2,\,\ldots,\,N\), respectively: \(g(j)=\text{bitvor}(Y(j),\,c(j))\). \[\mathbf{C}(I(i),:)=\text{bitvor}(\text{mod}(\mathbf{P}(i,:)+\mathbf{S},\,256), \,\mathbf{g}). \tag{15}\]  
Figure 6: A diagram for calculating the row vector \(\mathbf{S}\). (a) For calculating the row vector \(\mathbf{S}^{(0)},(\mathbf{b})\) for calculating the row vector \(\mathbf{S}^{(0)}\) (\(1\leq I<M\)). Equation (15) completes the encryption processing of the \(i\)-th row \(\mathbf{P}(i;\cdot)\) and gets the pixel sequence \(C(I(i),\cdot)\) of the \(I(i)\)-th row of the encrypted image. It can be seen that the \(i\)-th row of the image \(\mathbf{P}\) is arranged to the \(I(i)\)-th row of the encrypted image \(\mathbf{C}\), where the position transformation occurs, that is, the scrambling effect of the position is produced. In addition, the pixel value of the \(I(i)\)-th row of the encrypted image \(\mathbf{C}\) is different from the pixel value of the \(i\)-th row of the image \(\mathbf{P}\), that is, the substitution effect of pixel value is produced. Therefore, Equation (15) achieves both image row scrambling and pixel value substitution encryption. \[\mathbf{c}=\mathbf{C}(I(i),\cdot). \tag{16}\]  
Equation (16) updates the value of row vector \(\mathbf{c}\) to the currently encrypted image row \(\mathbf{C}(I(i),\cdot)\) in preparation for generating the intermediate key sequence \(\mathbf{g}\) of the next row. Thus, it can be seen that the intermediate key sequence \(\mathbf{g}\) used in the encryption of the \((i+1)\)-th row of image \(\mathbf{P}\) is related to the ciphertext row \(\mathbf{C}(I(i),\cdot)\). This mechanism brings two advantages. First, it can produce the effect of diffusion, which makes the ciphertext sensitive to the change of plaintext (if only one pixel in the plaintext image \(\mathbf{P}\) changes slightly, almost all pixels in the ciphertext image \(\mathbf{C}\) will change); that is, the ciphertext is sensitive to plaintext, which can improve the ability of the algorithm to resist differential cryptanalysis. Secondly, the intermediate key sequence \(\mathbf{g}\) is related to the image content, which allows the algorithm to resist the chosen-plaintext attack.