# 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  
In the row-by-row encryption processing stage, a row vector \(\textbf{S}^{(i)}=[S^{(i)}(1),\,S^{(i)}(2),\,\ldots,\,S^{(i)}(N)]\) related to the encrypted image content is used (superscript \((i)\) stands for the \(i\)-th row). Before entering the row encryption stage \((i=0)\), the row vector \(\textbf{S}^{(i)}\) takes the initial value \(\mathbf{S}^{(0)}\). The initial value \(S^{(0)}(i)\) of any element in \(\mathbf{S}^{(0)}\) is equal to \(k\) times of the sum of all the elements in the \(j\)-th column of the current image \(\mathbf{P}\) to be encrypted, which can be calculated with the following Equation (10), and the calculation principle can refer to Figure 6a. \[S^{(0)}(j)=k\times\sum_{i=1}^{M}P(i,j), \tag{10}\]  
where \(k\) is a positive integer greater than or equal to 1. By introducing parameter \(k\), the change effect of pixel value \(P(i,j)\) can be amplified. When the \(i\)-th row of the input image is encrypted, the value of any element \(S^{(i)}(j)\) in the vector \(\mathbf{S}^{(i)}\) is equal to \(k\) times of the sum of all elements whose row numbers are greater than \(i\) in the \(j\)-th column of the currently encrypted image \(\mathbf{P}\). The calculation principle of the vector \(\mathbf{S}^{(i)}\) is schematically shown in Figure 6b and can be expressed by the following Equation (11):  
\[S^{(i)}(j)=k\times\sum_{i^{\prime}=i+1}^{M}P(i^{\prime},j), \tag{11}\]  
when the last row of the input image \(\mathbf{P}\) is encrypted (\(i=M\)), all the element values in the vector \(\mathbf{S}^{(i)}\) are already equal to 0, that is, \(\mathbf{S}^{(M)}=[0,0,\dots,0]\). Observing the general formula (11) of \(\mathbf{S}^{(0)}\), we can get the following relation:  
\[S^{(i)}(j)=k\times\sum_{i^{\prime}=i+1}^{M}P(i^{\prime},j)=k[\sum_{i^{\prime}= i}^{M}P(i^{\prime},j)-P(i,j)]=k\times\sum_{i^{\prime}=i}^{M}P(i^{\prime},j)-k \times P(i,j),\]  
That is:  
\[S^{(i)}(j)=S^{(i-1)}(j)-k\times P(i,j). \tag{12}\]  
From the relation between \(\mathbf{S}^{(i)}\) and \(\mathbf{S}^{(i-1)}\) described by Equation (12), we can get a method to increase the speed of calculating the vector \(\mathbf{S}^{(i)}\); that is, it is not necessary to directly calculate the sum of all elements after the \(i\)-th row by the cumulative sum method of the Equation (11) for the vector used in each row, but the recursive algorithm can be used instead. Therefore, the \(j\)-th element value of the vector \(\mathbf{S}^{(i)}\) corresponding to the current row (\(i\)-th row) can be obtained by subtracting \(k\times P(i,j)\) from the \(j\)-th element value of the vector \(\mathbf{S}^{(i)}\) corresponding to the previous row (the (\(i\)-1)-th row). Only the element values of the initial vector \(\mathbf{S}^{(0)}\) must be directly calculated by the cumulative sum method of Equation (10). Therefore, the row vector \(\mathbf{S}^{(i)}\) needed to encrypt the \(i\)-th row can be calculated by the following algorithm: \(\mathbf{S}^{(i)}\)\(\leftarrow\)\(\mathbf{S}^{(i-1)}-k\times\mathbf{P}(i,:)\). Here, \(\mathbf{P}(i,:)\) represents a one-dimensional array composed of all elements in the \(i\)-th row of image \(\mathbf{P}\) to be encrypted. Therefore, the Equation (12) with elements as operating units can be rewritten as the calculation Equation (13) with an array as operating units:  
\[\mathbf{S}^{(i)}=\mathbf{S}^{(i-1)}-k\times\mathbf{P}(i,:). \tag{13}\]  
Executing Equation (13) is equivalent to executing Equation (12) for \(j=1,2,\dots,N\) in turn. In this way, a single row is treated as a single unit, turning an internal \(N\) times loop into a single loop. 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\}\).