# Hybrid Chaotic-Based PRNG for Secure Cryptography Applications
## 4 Proposed Encryption Algorithm
### Encryption Steps  
The proposed image encryption algorithm is based on a permutation-confusion process that utilizes the proposed chaotic function as its core pseudorandom number generator (PRNG) with different keys \(k_{1}\) and \(k_{2}\). The overall key \(K\) is composed of two subkeys, \(k_{1}\) and \(k_{2}\), each of which has a length of 128 bits, with the least significant 64 bits representing the parameter \(x_{0}\) and the most significant 64 bits representing the parameter \(c\). The generation of these keys is performed through the following steps:  
_Step 1: Key generation_  
The 256-bit sequence, referred to as the hash, is generated using the SHA-256 algorithm, which is a cryptographic hash function that takes an input of any length and produces a fixed-size output of 256 bits. Key \(k_{1}\) uses the least, i.e., 128 bits, and \(k_{2}\) uses the most, i.e., 128 bits. The values of \(x_{0}\) and \(c\) for each key are derived from the hash using Equation (6) to Equation (9). In these equations, \(x_{0,k_{1}}\) and \(c_{k_{1}}\) denote the _Least_ and _Most_ 64 bits of \(k_{1}\), respectively. Similarly, \(x_{0,k_{2}}\) and \(c_{k_{2}}\) represent the _Least_ and _Most_ 64 bits of \(k_{2}\), respectively. The presence of \(2^{64}\) in the denominator of all equations ensures that the resulting value falls  
Figure 6: Lyapunov exponent of the function in (4) showing positive values in the range of \(-2\leq c\leq 0\). within the range [0,1). By multiplying this value by 2 in Equations (7) and (9), the range is extended to [0,2). \[x_{0,k_{1}}=\frac{\sum\limits_{i=0}^{63}2^{i}\cdot hash(i+1)}{2^{64}} \tag{6}\]  
\[c_{k_{1}}=\frac{2\cdot\sum\limits_{i=0}^{63}2^{i}\cdot hash(i+65)}{2^{64}} \tag{7}\]  
\[x_{0,k_{2}}=\frac{\sum\limits_{i=0}^{63}2^{i}\cdot hash(i+129)}{2^{64}} \tag{8}\]  
\[c_{k_{2}}=\frac{2\cdot\sum\limits_{i=0}^{63}2^{i}\cdot hash(i+193)}{2^{64}} \tag{9}\]  
These equations ensure that \(x_{0}\) and \(c\) stay in the ranges \(0\leq x_{0}\leq 1\) and \(0\leq c\leq 2\). _Step 2: Permutation stage_  
In the permutation stage, a simple and effective algorithm is used to break the correlation between adjacent pixels in the message image, which is an important step for securing the scheme against statistical attacks. This is achieved by using the dimension of the original image \([M\times N]\) and the subkey \(k_{1}\) to generate a sequence using the function \(f(k_{1})\). The permuted pixels are then sorted based on this generated sequence. The permutation process starts by reading a grayscale message image (\(I_{m}\)) with size \([M\times N]\). Each pixel in the image is converted to its binary form \((B)\). The image is then reshaped into a 1D array. The sequence is generated from a pseudorandom number generator (PRNG) using Equation (4) with a length of \(W\times n\), where \(n=M\times N\) and \(W\in\{3,4,5,6\}\). The subsequence of length \(n\) is extracted from this generated sequence. This subsequence is sorted while keeping the sorted element original index. The pixels in 1D \(I_{m}\) are also sorted based on this generated sequence. _Step 3: Confusion stage_  
In the confusion stage, the goal is to increase the resistance against differential attacks by ensuring that any small change in the original image leads to nonuniform spreading across the ciphered image. To achieve this, a stream \(y_{i}\) is generated from the function \(f(k_{2})\) and used to replace the bit level value of each encrypted pixel using Equation (10):  
\[C_{i}=I_{m_{i}}\oplus floor(mod(y_{i}\;times10^{4},256)) \tag{10}\]  
where \(I_{m}\) is the permuted pixels, \(y\) is the generated subsequence, and \(C_{i}\) is the resulting image after the confusion step. This equation generates a confused image by performing an XOR operation on each pixel value with a value in the range of 0-255 derived from the \"\(floor(mod(y_{i}\;times10^{4},256))\)\" part of the equation.