# Implementation of MS Circle Map in Digital Image Encryption
## 2 Materials and Methods
### Encryption and Decryption Algorithms  
The encryption process was performed on the original image (confidential data) using the keystream generated by the MS Circle Map chaos function. The encryption process can be seen in Figure 3 and the decryption process in Figure 4. The encryption methods of digital images are as shown in Figure 3. The encryption process begins by generating the keystream using the MS Circle Map function. The number of keystream elements required is M \(\times\) N, according to the number of pixels in the plain image. The keystream is generated using Equation (4) by entering the key parameter values first, then the keystream will be generated. Because the MS Circle Map function uses the modulo 1 (mod 1) operation, the resulting keystream is a real number that lies between 0 and 1. To convert it to an integer with a value of 0 to 255, the keystream was then multiplied by 106. After that, the result was floored to remove fractional values and obtain a series of integers. Furthermore, from this result, a modulo 256 (mod 256) operation was performed, so that the final result of the keystream conversion can be substituted into each image pixel that has a value in the range of 0 to 255. \begin{table}
\begin{tabular}{l c c} \hline \hline
**Type of Test** & \(\mathbf{p}\)**-Value** & **Conclusion** \\ \hline Frequency Test (Monobit) & 0.977662 & Pass \\ Frequency Test within a Block & 0.567429 & Pass \\ Run Test & 0.356528 & Pass \\ Longest Run of Ones in a Block & 0.743168 & Pass \\ Binary Matrix Rank Test & 0.622197 & Pass \\ Discrete Fourier Transform (Spectral) Test & 0.335273 & Pass \\ Non-Overlapping Template Matching Test & 0.735657 & Pass \\ Overlapping Template Matching Test & 0.500748 & Pass \\ Maurer’s Universal Statistical Test & 0.816673 & Pass \\ Linear Complexity Test Serial & 0.353947 & Pass \\ Serial Test & 0.521116 & Pass \\ Approximate Entropy Test & 0.706375 & Pass \\ Cumulative Sums (Forward) Test & 0.900518 & Pass \\ Cumulative Sums (Reserve) Test & 0.838476 & Pass \\ Random Excursion Test & 0.505771 & Pass \\ Random Excursion Variant Test & 0.254903 & Pass \\ \hline \hline \end{tabular}
\end{table} 
Table 1: NIST randomness test result of the MS Circle Map. Figure 3: Digital image encryption process based on MS Circle Map. The next step is the substitution encryption process using the XOR operation between the pixel value (\(P_{ij}\)) at the coordinate position (_i,j_) of the plain image with one keystream element value in pairs. The XOR substitution operation was carried out pixel by pixel using Equation (5), starting from the first pixel to the last pixel until the encrypted image is obtained. \[C_{ij}=P_{ij}\bigoplus KS_{n} \tag{5}\]  
in which \(KS_{n}\) is the \(n\)th key in the keystream \(KS\), and \(C_{ij}\) is the pixel cipher value (encrypted pixel value) located at coordinates (_i,j_). The implementation of the image encryption chart in Figure 3 can be performed using Algorithm 1. In steps 3 to 6, the user can choose which keystream element will be used in the encryption process by entering the value t. Steps 7 to 14 show the keystream generation process, referring to Equation (4) (steps 9 and 10) and also the pixel-by-pixel encryption process based on Equation (5) (step 11). Despite this quadratic complexity, the algorithm remains computationally feasible for practical image sizes due to its efficient keystream generation and XOR-based operations. ```
Input: parameters \(x_{0},\ \lambda,\Omega,\ K,\ r,t\) and plain image \((P_{ij})\) Output: Encrypted Image \((C_{ij})\)
1. Enter all the parameter values of MS Circle Map and plain image \((P_{ij})\) with size \(M\times N\)
2.\(n=0\)
3. While \(n\leq t\) do
4. Calculate \(x_{n+1}\) use Equation (4)
5.\(n=n+1\)
6. Endwhile
7. For i = 1 to M
8. For j = 1 to N
9. Calculate \(x_{n+1}\) use Equation (4)
10.\(KS_{n}=\left\lfloor x_{n+1}\times 10^{6}\right\rfloor\ mod\ 256\)
11.\(C_{ij}=P_{ij}\oplus KS_{n}\)
12.\(n=n+1\)
13. Endfor j
14.