An image encryption algorithm based on a 3D chaotic Hopfield neural network and random row–column permutation

This study proposes a novel color image encryption algorithm based on a 3D chaotic Hopfield neural network and random row–column permutation. First, a 3D chaotic Hopfield neural network is proposed to produce the random sequence for generating the diffusion and permutation keys. Then, the rows and columns of the original image are randomly arranged according to the permutation key in the permutation process. Three subgraphs are formed by separating the R, G, and B components of the color image in the diffusion process. Each of the three subgraphs is split along the columns to form three parts; the left and middle parts are exchanged. Three diffusion keys are used to encrypt each of the three parts. Finally, the individually encrypted subgraphs are stitched together to obtain the final encrypted image. Simulation results using MATLAB and FPGA and security analysis demonstrate that the encryption scheme has good performance.


Introduction
In recent years, communication technology has made significant progress. At the same time, the security of information distribution has been raised to a new level. Digital images are an important means of multimedia expression [1,2], which are widely used in clinical medicine, astronomy, inspection, and other regions. In conclusion, image information transmission urgently needs a set of new, more stable, not-easy-to-be-cracked image encryption algorithms.
Chaos is a non-linear dynamical phenomenon that exists in a wide variety of natural fields [3][4][5][6], such as biology, meteorology, and economics. Interestingly, chaos is not a pure disorder but rather an ordered state that does not possess periodic changes and other notable symmetrical features. One distinctive feature of chaotic systems is that they are extremely sensitive to the initial values and parameters, and the dynamics and values of the system can vary considerably for different initial values of the same parameters. These characteristics of chaotic systems are well suited to the needs of image encryption algorithms [7,8], and that is the reason why many researchers have applied chaotic systems to image encryption in recent years. Wang et al. [9] proposed a new image-encryption algorithm based on iterating chaotic maps. Using the pseudorandom sequence generated by a group of one-dimensional chaotic maps, Li et al. [10] used a 1-D chaotic tent map to generate a chaos-based key stream for OPEN ACCESS EDITED BY Viet-Thanh Pham, Ton Duc Thang University, Vietnam image encryption. Lai et al. [11] proposed a novel image encryption based on the 2D Salomon map.
Many image-encryption studies now combine chaotic systems with other methods, such as DNA sequences [12][13][14][15] and diffusionpermutation [16][17][18]. Enayatifar et al. [15]proposed a novel imageencryption algorithm based on the deoxyribonucleic acid (DNA) masking hybrid model, genetic algorithm (GA), and logical map. Chai et al. [19]designed an encryption algorithm based on a chaotic system and DNA sequence operations. Liu et al. proposed an image-encryption algorithm based on one-time keys and robust chaotic maps and designed a novel encryption algorithm based on the spatial bit-level permutation and high-dimension chaotic system in Refs. 20, 21, respectively. Chen et al. [22] proposed a complete cryptosystem, which is built by using Bake maps for image permutations, and Diab et al. [23] improved it.
In recent years, some research studies on artificial neural networks and their applications [24][25][26][27][28][29] have been widely discussed. With the creation of the first memristor [30], many researchers have used memristors to simulate synapses [31][32][33] between neurons in the human brain and to analyze the dynamical behavior [34][35][36][37][38] of artificial neuronal networks. The combination of chaotic systems and artificial neural networks has become a hot research topic nowadays [39,40], and due to the nonlinear characteristic of the Hopfield neural network model, this model is capable of generating abundant chaotic behavior and is often used by researchers to simulate the various dynamic behaviors of neurons in the brain [41]. Using the Hopfield chaotic neural network model, a random sequence can be generated, and the more random the generated random sequence, the better the encryption of the image. There are many works in the field of random number generation using chaotic models [42,43]. Wang et al. [44] proposed a novel encryption algorithm based on a new fractional-order chaotic system. Before our work, Wang et al. [45] proposed a new color image encryption, which uses Hopfield chaotic neural networks to generate the self-diffusion chaotic matrix. Chen et al. [46] proposed a threedimensional fractional-order discrete Hopfield neural network. Wu et al. [47] applied the Hopfield chaotic neural network together with the novel hyperchaotic system to propose a new color image encryption algorithm. The purpose of this study is to investigate a simple but efficient image-encryption algorithm based on a chaotic Hopfield neural network model. This study proposed an image encryption based on a 3D chaotic Hopfield neural network and random row-column permutation. In this diffusion process, we separate the RGB components of the color image. Each component is split into three equal parts along the columns and then the middle and left parts are swapped. Three different random sequences are obtained by the proposed chaotic Hopfield neural network to encrypt the three parts of each component. Finally, the R, G, and B components of the ciphertext image are combined into the ciphertext image. Most of the previous image-encryption algorithms [48][49][50][51] either encrypted the RGB components using the same set of random sequences or encrypted the RGB using three different sets of random sequences separately. The association of each element of RGB in the relative position of the image is ignored, which would make the image easier to crack. Therefore, this study splits the RGB subgraphs separately and then uses different encryption sequences for each part of the subgraph. The experimental results are obtained by using MATLAB and FPGA. The extensive security analysis shows that the proposed algorithm improves encryption efficiency and has good security performance.
The rest of this paper is organized as follows. Section 2 describes the Hopfield neural network system. Section 3 presents the imageencryption and -decryption algorithm. Section 4 shows the simulation result of the image encryption and decryption. Section 5 analyzes the safety of this algorithm. Section 6 concludes this paper.

Hopfield neural network systems
The Hopfield neural network was proposed by the American physicist J. Hopfield [52]. In this study, the Hopfield neural network model of three neurons with self-feedback is adopted. We can see that the three neurons have the ability to connect together and influence each other. The Hopfield neural network model is shown as follows: where x i (t) represents the state variable of the i − th neuron. i = 1,2,. . .,n. U i is the activation function, and w [w ij ] nxn is the weight matrix.
In this study, the weight matrix [53] is expressed as follows: The weight matrix w is obtained through constant exploration and verification. The initial states of the system are x 1 (0), x 2 (0), and x 3 (0). The system state changes continuously under the action of the weight matrix and the excitation function. After continuous iteration, the system gradually enters a chaotic state. The 3D chaotic Hopfield neural network of this study can be presented as follows: where x 1 (t), x 2 (t), and x 3 (t) represent the state variables of the three neurons, respectively, and the activation function U i is represented as follows: Equation 3 represents first-order ordinary differential equations. With the forementioned weight matrix (2)  The initial values are chosen as follows: x 1 0 ( ) −0.215, x 3 0 ( ) mod sum p′, all′ , 10 + 1530 1000 , where sum represents the function of summing over pixel values, p represents the 3D array of plaintext images, and mod represents the residual function. The phase diagrams of the system are shown in Figure 1, and the initial values of the system are x 1 (0) = −0.123, x 2 (0) = −0.127, and x 3 (0) = 1.530, respectively. The neural network system consisting of three neurons enters a chaotic state with the presence of chaotic attractors.
To further confirm whether the system is in a chaotic state, we take the method of whether there exists a positive Lyapunov exponent [54] to judge. As the weights are determined and the initial values of the system are changed slightly, the Lyapunov exponent is always larger than zero. So, we can consider the proposed Hopfield neural network as a chaotic system [55].

Image-encryption and -decryption algorithms
In this section, the encryption process and decryption process of images are introduced.

Image encryption
Images are made up of pixels in electronics and are divided into color and grayscale images. Each pixel of a grayscale image contains only one pixel value, while every pixel of a color image consists of three pixel values of RGB. The grayscale image can be regarded as a two-dimensional array that contains the horizontal coordinates, vertical coordinates, and pixel value information for every pixel. The color image can be considered a three-dimensional array that contains the horizontal coordinates, vertical coordinates, and the RGB pixel values of every pixel. This study proposes a method to separate the RGB components of the color image and then perform the encryption operation. Equation 6 is used to separate the RGB component of the color image, which is shown as follows: where P represents the original image. PR, PG, and PB represent the R, G, and B components of the original image, respectively. This study proposes an image-encryption algorithm based on a 3D chaotic Hopfield neural network and random row-column permutation. Row-column permutation is the process of changing the position of the pixel without changing the value. The chaotic sequences are generated by the proposed chaotic Hopfield neural network for producing the permutation keys and diffusion keys. In the permutation process, the positions of the ranks of the pixels will be changed according to the permutation keys. Image diffusion is the process of changing the pixel values of RGB with the diffusion keys.
The chaotic sequences are obtained through continuously iterating the proposed 3D chaotic neural network system. The length of the intercepted chaotic sequences depends on the number of pixels in the image. Here, the first 3,000 numbers should be removed from the sequences, which are generated before the chaotic neural network system is stabilized with some error and poor randomness. The intercepted sequences will stay within the interval [0,255] by taking the absolute value, expanding by 10 15 , and taking the remainder. The permutation keys and diffusion keys are both obtained from the chaotic sequences.
The encryption algorithm in this study consists of two main steps: random row-column permutation and image diffusion. Details of the process can be described as follows: First, the rows and columns of the image are distorted through the permutation keys. Next, the RGB components of the image are separated by the method shown in Eq. 6. Each subgraph is formed by dividing the RGB components into three parts along columns and exchanging the middle and left part. The three parts of the subgraphs are encrypted with three different sets of diffusion keys. Finally, the subgraphs are synthesized to yield the encrypted images. The image encryption flowchart is shown in Figure 2

Permutation process
The process of image permutation is to change the position of the image pixels without changing the values. First of all, the chaotic sequences are generated by the 3D chaotic Hopfield neural Frontiers in Physics frontiersin.org network (3) for producing the permutation keys, which are combined with the increasing sequences of length and width of the corresponding image to form 2 × M and 2 × N key pairs, respectively. Then, the permutation process is achieved by the determinant transformation of the original image through the key pairs.
Step 1: The length M and width N of the image are obtained at first. Then, the chaotic sequences x 1 (i) and x 2 (j) (i = 1,2,. . .,M and j = 1,2,. . .,N) are generated through the 3D chaotic Hopfield network system, respectively.
Step 2: The permutation keys are obtained through the chaotic sequences, and the expression of the generated function is as follows: where RandM(i) and RandN(j) (i = 1,2,. . .,M and j = 1,2,. . .,N) represent the permutation keys of the row and column, respectively. The floor is the downward-rounding function. x 1 (i) and x 2 (j) are the chaotic sequences.
Step 3: Duplicate numbers are discarded when the permutation keys are obtained. For each number stored in RandM(i) or RandN(j), the corresponding position variables i or j increases by 1. This step is repeated until i and j have reached the values of M and N, or the chaotic sequences have been taken.
Step 4: The numbers in RandM(i) and RandM(j) are complemented because there is no guarantee that all nonrepeating numbers from 1 to M or 1 to N will be taken; we need to find numbers that do not exist in the arrays and add them to the arrays until they are filled Step 5: The key pairs are formed through the permutation keys and increasing sequences. The generating function of the key pairs is shown as follows: Specifically, Mchange and Nchange are 2 × M and 2 × N arrays, respectively. The first row is an increasing sequence of 1~M or 1Ñ , and the second row is the sequence of RandM(i) or RandM(j), respectively. Ultimately, the mappings are formed by key pairs to perform permutation.
Step 6: The rows and columns of pixels are randomly permutated to get the permuted image. The permutation method can be shown as follows: The outline and main information of the permuted image are obscured after this process. However, there is still some plaintext image information that can be captured by illegal hackers. At the same time, the correlation between the pixel points of the adjacent is still at a high level. To make the encryption system works better, the diffusion process is performed.

Segmentation and diffusion process
The difference between image permutation and image diffusion is that image diffusion needs to change the original pixel value, which will completely distort the information of the whole image. The main information and details of the image are completely invisible, and the cryptographer cannot find any useful information.
Three subgraphs are generated by separating the R, G, and B components of the color image in the diffusion process. Each subgraph is split along the columns to form three equal parts. The primary information of the daily photos or machine-made images is usually centered. So, the left and middle parts are exchanged in this process. Three different chaotic sequences y 1 , y 2 , y 3 are obtained through the 3D chaotic Hopfield neural network system to produce the diffusion keys, which are used to encrypt the three parts, respectively. The experimental results obtained using MATLAB and FPGA prove that our proposed encryption algorithm has a good encryption effect. The detailed steps are as follows: Step 1: First, RGB components of the permuted image are separated to form three subgraphs, which are divided along columns into three parts to exchange the left part and middle part. Three parts of the RGB components are generated by Eq. 10: where j 1 = 1,3. Step 2: The diffusion keys are obtained by Eq. 11: where n 1 = 1,2,. . ., floor N 3 , n 2 1, 2, . . . , N − floor 2N 3 , and n 3 1, 2, . . . , floor 2N 3 − floor N 3 .
Step 3: Three different diffusion keys are used to encrypt the three parts of the subgraph, which is shown as follows: where CLR, CCR, and CRR represent the left, middle, and right parts of the encrypted subgraph R, respectively. bixor(P, k) represents the XOR operation. The pixel value of the cipher image is formed by the XOR operation between the original pixel value and the diffusion key. The information in the plaintext image is completely hidden.
Step 4: Splicing the three encrypted parts of the subgraph together, we get where CR represents the R component of the ciphertext image. The positions of CCR and CLR are exchanged to obtain a better encryption effect.
Frontiers in Physics frontiersin.org Step 5: Step 1 to Step 4 is repeated to realize the encryption of the G and B components.
Step 6: The encrypted RGB components are combined to form the final encrypted image. Furthermore, three two-dimension arrays are merged into one three-dimensional array, which is shown as follows: where C represents the ciphertext images after the diffusion process and cat represents the splicing function.

Image decryption
The image decryption is the inverse process of the image encryption. In this process, the ciphertext image is obtained at first. Then, the R, G, and B components of the ciphertext image are divided into three parts by columns, and then the middle part and left part are exchanged. After that, the inverse diffusion process is performed, and the RGB components are stitched to obtain the complete images. In image encryption, the column-transformed operation happens behind the row-transformed operation in the permutation process. So, the inverse operation is done in the inverse permutation process. Finally, the plaintext image is obtained. The flowchart of the image decryption is shown in Figure 3.

Simulation results
In this study, we selected four color images with a resolution of 512 × 512 for encryption.

Simulation results using MATLAB
The images with a clear outline, dense pixel distribution, uniform color, and uniform light and dark are selected as the test images because they are representative and better reflect the performance of the encryption algorithm. From Figure 4, we can see that the outline of the ciphertext image is invisible, and the pixels are equally distributed. So, it is almost impossible to obtain plaintext image information from the ciphertext image. The decrypted image is exactly the same as the plaintext image. It can be said that the encryption algorithm has excellent encryption performance.

Simulation results in FPGA
In this section, FPGA-based implementation of the proposed image cryptosystem is introduced. We have implemented FPGA debugging by using a Xilinx Zynq-7000 series XC7Z020 FPGA chip and an AN9767 dual-port parallel 14-bit digital-to-analog converter module with a maximum conversion rate of 125MHz, Vivado17.4,  Frontiers in Physics frontiersin.org 07 module, which is used to generate the ciphertext image. The image encryption module consists of the image permutation process and the image diffusion process module. The image decryption module is the inverse of the encryption module and decrypts the ciphertext image into a plaintext image. The image display controller module is used to display both plaintext and ciphertext images.
FPGA-based implementation result of the proposed image cryptosystem is shown in Figure 6. From Figures 6A, B, the plaintext image and the encrypted image are shown on the screen. The images on the right in Figure 6A and on the left in Figure 6B are the permutated images, and the image on the right in Figure 6B is the ciphertext image. Figure 6C is the decryption result of the FPGA-based implementation. Experiments have demonstrated no significant difference between the FGPA platform and MATLAB regarding the effectiveness of image encryption and decryption.

Performance analysis
This section is to verify the security and efficiency of the proposed encryption algorithm. The simulation test is performed on a computer using MATLAB R2020b.

Histogram analysis
The histogram can reflect the distribution of the overall pixel values of the image accurately and intuitively. There is only one component of the pixel value in a grayscale image, so the greyscale image has only one histogram. However, the pixel value of the color image consists of R, G, and B components. Therefore, a color image has three histograms, representing the occurrence of R, G, and B pixel values, respectively. The histogram is a two-dimensional statistical map, where the abscissa represents each pixel value in the color image and the ordinate indicates the frequency of each pixel value appearing in the color image. The analysis of the histogram can capture information about the images. The encryption system with high security should make the histograms of the ciphertext image as uniform as possible. Four color images are selected for histogram analysis; the histograms of plaintext images are shown in Figures 4E-H, and  The histograms of R, G, and B components of the plaintext images show a mountainous pattern with an uneven distribution of the pixels, while the histograms of the ciphertext images are very uniform and the characteristics of the distribution of the image pixels are well hidden. It is difficult for a cracker to obtain any useful information from the histograms. It can be inferred that this encryption scheme has great security.

Correlation analysis
Correlation analysis reflects the degree of correlation of pixel values at adjacent positions in the image. The size of the correlation coefficient of adjacent pixel values in the ciphertext image can better reflect the effects of the encryption algorithm. The lower the correlation, the better the encryption effects of the ciphertext image obtained by the proposed encryption algorithm. The correlation coefficient of a good color image-encryption algorithm should be close to zero. The correlation analysis equation is as follows: where u i and v i represent the adjacent pixel values in the image and n is the number of pixels sampled. E(u) and E(v) represent the expectation of u and v. cov(u, v) represents the covariance, and r is the correlation coefficient. The correlations should be analyzed in the R, G, and B components separately in the color images, and we need to analyze the four directions of the image: horizontal, vertical, positive-diagonal, and negative angles. Here, 10,000 pixels of the components R, G, and B are randomly taken. If the coordinate point of u i is (x i , y i ), then the adjacent coordinate point in the horizontal direction is set to v i (x i + 1, y i ). Similarly, the adjacent coordinate point we set in the vertical direction is v i (x i , y i + 1), in the positivediagonal direction; we set v i (x i + 1, y i + 1), and the adjacent coordinate points in the opposite angular direction were set as v i (x i − 1, y i + 1).
The correlation coefficient of the plaintext image is almost close to 1, which indicates that the correlation of the pixels in the plaintext image is extremely strong. However, the ciphertext image is almost close to 0, indicating the adjacent pixels in the ciphertext image have almost no correlation. The correlation test in plaintext and ciphertext images is shown in Figure 7, which contains the distributions in those four directions, respectively. The ciphertext image shows the irregular distribution in four directions, and the pixel values around each pixel point are arbitrarily random. However, most of the points in Figures 7A, C, E, G are around a straight line, indicating there is a significant correlation in the plaintext image.
The results of the correlation coefficient in different directions are shown in Table 1. We can see that the proposed scheme has a remarkable performance. Only one of the correlation coefficients obtained by the proposed algorithm is higher than others.

Analysis of information entropy
Information entropy is an index to evaluate the performance of the encryption algorithm. The higher the information entropy index, the better the performance of this encryption algorithm. The information entropy equation is as follows: where P(i) represents the probability of the occurrence of the pixel value of i. The ideal entropy for the R, G, and B components of the color image should be equal to 8. The color Lena graph, Baboon graph, Pepper graph, and plane graph are chosen as the test images, which are encrypted by the proposed encryption algorithm. The information entropy of R, G, and B components are analyzed by Eq. 16. The test results are shown in Table 2.
The table clearly shows the information entropies of the R, G, and B components of the encrypted images Cipher-Lena, Cipher-Baboon, Cipher-Pepper, and Cipher-plane. The entropies obtained by the proposed algorithm are close to the ideal value. From Table 3, we can see that most of the entropies are larger than those obtained by other algorithms. This feature prevents information leakage during the encryption process. So, we can infer that the proposed algorithm is significantly secure.

Analysis of PSNR and MSE
PSNR and MSE are used to describe the difference between the original and encrypted images. The greater the difference between the plaintext image and the ciphertext image, the better the performance of the encryption algorithm. PSNR is the peak signal-to-noise ratio, which is an index of distortion Frontiers in Physics frontiersin.org between the plaintext and ciphertext images. The lower the PSNR value, indicating that the greater the difference between plaintext and ciphertext images, the better the encryption algorithm is.
MSE is the mean squared error, which is used to calculate the cumulative squared error between plaintext and ciphertext images. The larger the MSE, the better the encryption effect. The PSNR and MSE are defined as follows: where P and C represent the plaintext and the ciphertext images, respectively. In addition, (i,j) stands for the position of each pixel.
The comparison of PSNR and MSE among the proposed and other algorithms is shown in Tables 4, 5, respectively. Most of the PSNR and MSE indices of our proposed algorithm are superior compared to those of others. The results show that the proposed encryption scheme has better performance.

Sensitivity analysis
Sensitivity analysis is decrypting the encrypted image with the keys whose initial values are slightly different from the original keys to see if the encrypted image can be decrypted correctly. The Lena plaintext image is encrypted by using the keys. Then, the ciphertext image is decrypted with the pseudo-keys of three very close key values Y 1 , Y 2 , and Y 3 , respectively. The initial values of the pseudo-keys are as follows:  Frontiers in Physics frontiersin.org where x 1 (0), x 2 (0), and x 3 (0) are the initial values of the keys. The three aforementioned sets of pseudo-keys with slightly different initial values are used to decrypt the Lena ciphertext image. The results of decrypting are shown in Figure 8. The plaintext image cannot be recovered correctly. Therefore, the encryption system proposed in this study satisfies the requirement of key sensitivity.

Analysis of key space
A good image-encryption algorithm must have the ability to withstand outside attacks. Therefore, the key space must be large enough to ensure the security of the encryption algorithm. The key space of an ideal image encryption is larger than 2 100 .
The computer computational accuracy is about 10 15 , and the compression rate CR is 10 5 . In this study, the key generation process consists of the following: 1) the initial values of x 1 (0), x 2 (0), and x 3 (0) are used for the chaotic Hopfield system iteration and the sampling time point, and 2) chaotic sequences y 1 (t), y 2 (t), and y 3 (t) are also used. So the key space is calculated by Eq. 19: 10 2 × 10 15 × 10 14 × 10 14 × 10 14 × 10 14 × 10 14 × 10 14 × 10 14 ≫ 2 100 . (19) This shows that the encryption algorithm has a large enough key space to resist exhaustive attacks.

Conclusion
This study proposes a color image-encryption algorithm based on random row-column permutation and a 3D chaotic Hopfield neural network. The 3D chaotic Hopfield neural network is used to generate chaotic sequences to ensure the randomness of keys. After the permutation process, three subgraphs are formed by separating the R, G, and B components of the color image, and then, the subgraphs are cut along the columns for swapping the middle part and the left part. Three diffusion keys are produced through the chaotic sequence, and then the three parts of the subgraphs are encrypted separately. In this study, we consider the interrelationship of the pixel values of the RGB components in the plaintext image, so three sets of diffusion keys are used to encrypt the three parts of the split RGB subgraphs. This measure effectively reduces the interconnection of pixel values. Through extensive simulations and security analysis, the simulation results in MATLAB and FPGA show that the encryption algorithm has superior performance and high security.

Data availability statement
The original contributions presented in the study are included in the article/Supplementary Material; further inquiries can be directed to the corresponding author.

Ethics statement
Ethical review and approval were not required for the study on human participants in accordance with the local legislation and institutional requirements. Written informed consent for participation was not required for this study in accordance with the national legislation and the institutional requirements.