An Image Encryption Algorithm Based on Complex Network Scrambling and Multi-Directional Diffusion

Various security threats are encountered when keys are transmitted in public channels. In this paper, we propose an image encryption algorithm based on complex network scrambling and multi-directional diffusion. Combining the idea of public key cryptography, the RSA algorithm is used to encrypt the key related to plaintext. The algorithm consists of three stages: key generation stage, complex network scrambling stage, and multi-directional diffusion stage. Firstly, during the key generation phase, SHA-512 and the original image are used to generate plaintext-related information, which is then converted to plaintext-related key through transformation mapping. Secondly, in the complex network scrambling stage, the chaotic random matrix establishes the node relationships in the complex network, which is then used to construct an image model based on the complex network, and then combines pixel-level and block-level methods to scramble images. Finally, in the multi-directional diffusion stage, the multi-directional diffusion method is used to perform forward diffusion, middle spiral diffusion, and backward diffusion on the image in turn to obtain the final ciphertext image. The experimental results show that our encryption algorithm has a large keyspace, the encrypted image has strong randomness and robustness, and can effectively resist brute force attack, statistical attack, and differential attack.


Introduction
In this era of rapid development of information technology, a large number of digital images are transmitted on the network. The images contain a wealth of information, for example, the distribution of city buildings and crop growth can be understood in satellite images; medical images can reveal health status, age information, and so on. There are also images that contain sensitive information such as military secrets, commercial information, and government documents. Moreover, when images are transmitted in public networks, security threats such as interception, tampering, and copying may be encountered [1][2][3][4]. Therefore, the image security issue has attracted more and more attention from scholars.
Encryption of images is an effective method of securing images [5,6]. Traditional text encryption schemes are DES [7,8], AES [9], etc., and when using these schemes to encrypt images, it is necessary to first process the image into a bit stream [10], but this ignores the high information content, high redundancy, and high correlation between pixels [11][12][13]. Therefore, traditional schemes have drawbacks when encrypting images and are not suitable for image encryption [14,15]. Therefore, the development of new efficient and secure image encryption algorithms has become an important research topic in the field of security.
Since chaotic systems have characteristics such as initial value and parameter sensitivity, ergodicity, and unpredictability [16,17], these characteristics are well suited for image plaintext-related information [49]. Xu et al. designs an asymmetric image encryption scheme suitable for multi-user image transmission [50]. In this study, the key is protected using the Paillier algorithm, which is an asymmetric homomorphic encryption algorithm.
Based on the above discussion, an image encryption algorithm based on complex network scrambling and multi-directional diffusion is proposed in this paper. The algorithm uses a combination of symmetric encryption and asymmetric encryption. Among them, a symmetric encryption method is used for the image, while an asymmetric encryption method is used for the key. In the scrambling phase, pixel-level index scrambling is first performed on the image, followed by block-level scrambling of the image. In block-level disarrangement, a complex network is used to construct an image model, establish the relationship of nodes in the network based on the values of chaotic sequences, and then obtain the upper triangular matrix of the adjacency matrix of the network model, and finally, disarrange the image blocks. In the diffusion stage, forward diffusion, middle spiral diffusion, and backward diffusion are used for the images. The main contributions of this study are as follows: • A key protection method based on the RSA algorithm is designed to ensure the security of keys when they are transmitted over a common channel; • An image scrambling method based on complex network is designed. When building the network model, the image block is used as the node in the network. This method not only fully scrambles the image, but also reduces the computational complexity and storage space of the algorithm; • A multi-directional diffusion method is proposed to spread the diffusion effect from each pixel to the whole image.
The remainder of this study is structured as follows. Section 2 presents the relevant knowledge for this study. In Section 3, the proposed complex network-based scrambling method is described. Section 4 presents the proposed image encryption algorithm. Section 5 evaluates the experimental results and the security of the algorithm. Finally, Section 6 provides a brief summary of the whole paper.

A Discrete Four-Dimensional Chaotic System
The chaotic sequences produced by chaotic systems are often used in image encryption schemes using scrambling and diffusion. As the discrete four-dimensional chaotic system used in the literature [41] has good pseudo-randomness and unpredictability, the discrete chaotic system can generate simple and effective chaotic sequences. Therefore, this chaotic system is used in this paper to generate chaotic sequences as key streams. The chaotic system is defined as where x i (i = 1, 2, 3, 4) is the initial state of the chaotic system. All values of variables are limited to [−2,2], we set the initial state of the chaotic system as (x 1 (0), x 2 (0), x 3 (0), x 4 (0)) = (0.11, 0.12, 0.13, 0.14). Figure 1 shows the attractor of this discrete four-dimensional chaotic system. Figure 2 is the Lyapunov diagram of the chaotic system; it can be seen that its Lyapunov exponents are 0.3028, 0.0640, −0.5668, −1.7692. Since this chaotic system has two positive Lyapunov exponents, it is more difficult to decipher compared to other chaotic systems. Figure 3 shows the trajectory diagram of this discrete four-dimensional chaotic system. It can be seen from Figures 2 and 3 that this chaotic system has very good chaotic performance and can generate effective pseudo-random sequences. Therefore, this chaotic system is very suitable for image encryption.

RSA Algorithm
The RSA algorithm [51] is an encryption algorithm belonging to a public key cryptosystem. It has a simple encryption process and high security, and is widely used in many security fields. The procedure of the RSA encryption algorithm is described in Algorithm 1.
1: Randomly choose two large prime numbers p and q , compute n = p * q and ϕ(n) = (p − 1) * (q − 1). 2: Randomly select public key e, where 1 < e < ϕ(n) and gcd(e, ϕ(n)) = 1. 3: Calculate the private key d, where e * d = 1modϕ(n). Here, {e, n} is the public key, {d, p, q} is the private key. 4: The encryption process is c = m e (modn), and the decryption process is m = c d (modn).  In this paper, we adapt the complex network structure of Figure 4 to the network structure shown in Figure 5 in order to use the complex network for image scrambling. The adjustments made are as follows:

Scrambling Method Based on Complex Network
• For an image with M rows and N columns, considering the structure of the image, we restrict the nodes of the complex network to a rectangular space of the same size; • Some existing studies use each pixel point of an image as a node of a complex network, but images generally have a large number of pixel count points, and these methods suffer from the problem of large computational effort. In the proposed algorithm, we use image pixel blocks as nodes in the complex network model, which greatly reduces the number of nodes and improves the efficiency of the algorithm; • We set the connection probability of a node to φ, the degree of that node to α, the total degree of nodes in the network to s, and the total number of nodes in the network to κ. Then, the connection probability of each node is • To prevent nodes from being repeatedly connected, the connection probability of a connected node is set to 0; • To make random connections of nodes, we use the values of the pseudo-random series generated by the chaotic system and the connection probabilities of the nodes for random connection of nodes. After generating the complex network model, we obtain the adjacency matrix and the upper triangular matrix of the adjacency matrix of the network nodes from the generated complex network model. In order to reduce the computational effort of the algorithm, here, we traverse the upper triangular matrix of the adjacency matrix to swap the positions of the two nodes with matrix value of 1. Here, we provide an example to explain this part in detail. Figure 6 shows the process of permutation of a matrix MP of size 4 × 4. The numbers in the figure indicate that the matrix is first chunked. After that, the nodes are randomly connected according to the connection method of the nodes proposed above, then, the adjacency matrix and the upper triangular matrix of this network structure are obtained, and finally, the disordered matrix CMP is obtained by the upper triangular matrix.

The Proposed Algorithm
In this section, a new image encryption algorithm based on complex network scrambling and multidirectional diffusion is proposed. The encryption algorithm consists of three parts: key generation, image scrambling based on complex networks, and multidirectional diffusion of images, where the last two parts are used to change pixel positions and change pixel values, respectively. The flowchart of the proposed encryption\decryption scheme is shown in Figure 7. Below, we will describe the encryption process in detail.

Key Generation
As the hashing algorithm is very secure [52], in the proposed algorithm, we use the SHA-512 algorithm to generate the initial key for encryption. The plaintext image is first fed into the SHA-512 algorithm to obtain a sensitive hash value associated with the plaintext image, after which the key used for the dislocation and diffusion parts, respectively, is obtained through this hash value. This method establishes the correlation between the algorithm and the plaintext image, which can resist the chosen plaintext\ciphertext attack and improve the security of the encryption system. In addition, using different keys for the scrambling and diffusion parts further improves the security of the encryption system. The steps of key generation are as follows: • Input the original image P of size M * N into the SHA-512 algorithm to generate a 512-bit hash value K.
• The hash value K is partitioned into 64 parts, each containing 8 bits of data. Figure 8 shows the partitioning method of the hash value. • Use Equation (5) to calculate the first set of keys {x i (1)i = 1, 2, 3, 4} for the scrambling part of the encryption algorithm.
where represents the XOR operation. • Calculate the second set of keys {x i (2)i = 1, 2, 3, 4} using Equation (6), which is used for the diffusion part of the encryption algorithm.
For key transmission, we use the RSA algorithm to encrypt the key and ensure that the key is transmitted securely over the public channel. The {x i (1)i = 1, 2, 3, 4} and {x i (2)i = 1, 2, 3, 4} are encrypted into {c i (1)i = 1, 2, 3, 4} and {c i (2)i = 1, 2, 3, 4}, respectively, using the Paillier encryption algorithm. The receiver decrypts {c i (1)} and {c i (2)} before decrypting the ciphertext image. This method improves the security of the key when it is transmitted over a public network.

Scrambling Process
Based on the existing research, we apply the complex network method to the field of image encryption. Here, the BA scale-free network model is used to construct a model of a planar image and perform image scrambling based on it. The detailed steps in this section are explained below.

•
Input the first set of keys into the discrete four-dimensional chaotic system, and iterate M * N + n 0 times to generate four pseudo-random sequences. To eliminate transient effects, the first n 0 terms of each sequence are discarded, and finally, four pseudorandom sequences X1 1 , X2 1 , X3 1 , X4 1 of length M * N are obtained. • Sort the sequence X1 1 from smallest to largest to obtain the index sequence X1 1 _index.
• Pixel-level scrambling of the original image P using the index sequence X1 1 _index to obtain the first scrambled image P1. The scrambling method is expressed as • To further scramble the image and to eliminate the correlation between adjacent pixel blocks, the image is then scrambled by blocks using a complex network. P1 is The image blocking method is shown in Algorithm 2.
Algorithm 2 Image blocking method.

Input:
The image P1 to be blocked, the size of each image block M g * N g . 1: The initial number of nodes of the complex network model, the number of edges added at each new node, and the final size of the network are set to γ, η, ϕ. The initial nodes of the network model are set to be isolated. Each node in the network model corresponds to each chunk of the image. • In the proposed method, the coordinates of the initial nodes of the complex network are generated using a pseudo-random sequence X2 1 . Firstly, the element values in the sequence X2 1 are converted to integers between [1, M/M g ], after which two randomly selected sequences of length γ are used as the coordinates of the initial nodes. The generation method is where f loor() is a downward rounding operation.
• Generate new nodes, each connected to the previous η nodes, until the total number of nodes in the complex network model reaches ϕ. Assuming that the degree of a node is q and the total degree is q , the connection probability of the current node is (q + 1)/(q + 1), which solves the problem that the connection probability of isolated nodes is 0. When making node connections, the nodes are connected randomly using the element values in N_X3 1 according to the connection probability of the current node. In this paper, we setγ, η, and ϕ to 10, 4, and 256, respectively, and Figure 9 shows the graph of this complex network model. for j = 1 to N do 4: if A (i,j) == 1 then 5: end if 9: end for 10: end for 11: P2 = P1 b Output: Image scrambling result P2 An example is given here to illustrate the proposed scrambling method. We use a "Boat" image of size 256 × 256, and to explain the proposed method more clearly, we start from step 4. First, divide the "Boat" image into 16 blocks, each of size 64 × 64. Afterwards, the initial number of nodes of the complex network model, the number of edges added each time a new node is added, and the final scale of the network are set to 4, 4, and 16, respectively. Figure 10 displays the generated adjacency matrix and upper triangular matrix. Figure 11 shows the result of the generated complex network model and image scrambling.

Diffusion Process
An effective encryption algorithm should also have the diffusion property. In the algorithm proposed in this paper, we use a multi-directional diffusion method in order to obtain a good diffusion effect. The method consists of three parts: forward diffusion operating from the top left pixel of the image, spiral diffusion operating from the middle pixel of the image, and backward diffusion operating from the bottom right pixel of the image. To improve the security of the algorithm, a chaotic sequence closely related to the original image is used for each diffusion, while the chaotic sequence used for each diffusion is controlled by the value of the chaotic sequence. The specific diffusion steps are as follows: • Input the second set of keys {x i (2)i = 1, 2, 3, 4} into the discrete four-dimensional chaotic system, and also iterate M * N + n 0 times to generate four pseudo-random sequences. In order to eliminate transient effects, the first n 0 items of each sequence are discarded as in the previous method, and finally, four pseudo-random sequences X1 2 , X2 2 , X3 2 , X4 2 of length M * N are obtained. • Convert the values of pseudo-random sequences X1 2 , X2 2 , X3 2 , X4 2 to integers between [1, 255], and the conversion method is as follows • Intercept the sequence of length 6 from NX4 2 and modify the element values of the intercepted sequence to integers between [1, 3]. The sequence is divided into three groups, while the elemental values of each group are not the same, and the chaotic sequence used in image diffusion is controlled using the elemental values of one group of the sequence at a time.
• Perform forward diffusion operation on P2. Starting from the pixel in the top left corner of the image, the diffusion is performed pixel by pixel, from top to bottom, from left to right, ending with the bottom right corner of the image. The next value at the current position is updated with the previous pixel value and two chaotic sequence elements.
• Perform a spiral scan operation on P3, starting from the middle pixel of the image and scanning the image in a spiral manner to convert P3 into a one-dimensional matrix P3 , after which a pixel-by-pixel diffusion is performed starting from the first pixel of P3 and ending with the last pixel.
• Perform a backward diffusion operation on P4. The diffusion is performed pixel by pixel, starting from the pixel in the bottom right corner of the image, going from bottom to top, right to left, and ending with the top left corner of the image. C is the final encryption result.
To better explain this section, we provide an example of a detailed operation on an image of size 4 × 4. Figure 12 shows the process of the proposed diffusion method, where the numbers in the figure indicate the pixel values of the image.

Decryption Algorithm
After the sender encrypts the original image, the keys {x i (1)i = 1, 2, 3, 4} and {x i (2)i = 1, 2, 3, 4} are encrypted using the public key (n, g) obtained from the receiver and the RSA encryption algorithm. After that, the sender sends the ciphertext image C and the encryption keys c i (1)i = 1, 2, 3, 4 and c i (2)i = 1, 2, 3, 4 to the receiver. The receiver decrypts the keys using the private key (λ, µ) to obtain the initial values of the chaotic system x i (1)i = 1, 2, 3, 4 and x i (2)i = 1, 2, 3, 4, after which the chaotic sequences {X1 1 , X2 1 , X3 1 , X4 1 } and {X1 2 , X2 2 , X3 2 , X4 2 } are obtained by the discrete four dimensional chaotic system. Finally, the decrypted image P is obtained by the inverse process of the diffusion operation and the inverse process of the permutation operation.

Experimental Results and Performance Analysis
To verify the validity and security of the algorithm, simulations were performed using the Matlab platform on the Window 10 operating system. The selected sample images are grayscale images "Baboon" and "Peppers" with the size of 256 × 256 and color images "Boat" and "Sailboat" with the size of 256 × 256 × 3. Figure 13 shows the results of the simulation. It is clear from the experimental results that the encrypted image is a noise-like image, that it is visually impossible to get any information about the original image from the cipher image, and that a lossless decrypted image can be obtained with the correct key.

Keyspace Analysis
The encryption algorithm must be able to withstand brute force cracking by an attacker [53]. Theoretically, the algorithm is proven to be secure when the key space is larger than 2 128 . The key size of the proposed algorithm in this paper is 512 bits and each bit has 2 states. Therefore, the key space size of the proposed encryption algorithm is 2 512 (>> 2 128 ). As a result, the image encryption algorithm proposed can resist the brute force attack.

Key Sensitivity Analysis
Key sensitivity is a reliable way to measure the security of digital image encryption systems [54]. To test the key sensitivity of the proposed algorithm, we randomly modify the key K 1 generated in the algorithm to obtain two other keys-K 2 and K 3 . K 1 , K 2 , K 3 are denoted as The results of the key sensitivity analysis of the encryption process of the proposed algorithm are shown in Figure 14. Figure 14b,c show the encryption results using the keys K 1 and K 2 , respectively. Figure 14d shows the difference of the two encryption results. Figure 15 shows the experimental results of the key sensitivity of the decryption process. It can be seen that although the keys K 1 , K 2 , and K 3 differ by only one bit, the images produced during decryption are completely different. Figure 15e shows the difference between the decrypted images obtained using illegal keys with only minor differences. The experimental results can show that the proposed image encryption algorithm is highly sensitive to the key.

Information Entropy Analysis
Information entropy can be used to detect the degree of chaos in the distribution of image pixels. The formula for calculating information entropy is [55].
where P i denotes the frequency of occurrence of the pixel with value i. The ideal value of information entropy can be obtained when all pixels appear with equal probability. Thus, for an 8-bit image, the theoretical maximum value of information entropy is 8. Table 1 lists Figure 13a-d and the results of information entropy measurements after encryption of these images. From the experimental results, it can be seen that the information entropy of the cryptographic images is very close to the theoretical value, indicating that the proposed algorithm produces cryptographic images with good randomness. Table 2 shows the information entropy results of different algorithms using "Baboon" of size 256 × 256. In comparison, the encryption result in this paper is closer to the theoretical value. Therefore, the proposed algorithm has better resistance to information entropy analysis.

Histogram Analysis
The histogram tests the distribution of gray values in an image. In general, the original image histogram is fluctuating, while the histogram of an encrypted image is flat [61]. Good encryption algorithms produce cryptographic images with a very uniform distribution of pixel values. Figure 16 shows the results of the histogram analysis. As can be seen from Figure 16, the histograms of all encrypted images are smooth and uniform, indicating that the proposed algorithm hides the original image information and has the ability to resist histogram statistical attacks.

Adjacent Pixel Correlation Analysis
A good image encryption algorithm must be able to completely break the correlation of neighboring pixels in an image [62]. To verify the proposed algorithm, we choose Figure 13a and its cipher image Figure 13e as the test images. Figure 17 shows their adjacent pixel correlation distribution in horizontal, vertical, and diagonal directions. It is clear that the pixels of the original image are mainly distributed around y = x, while the pixels of the cipher image are distributed over the entire coordinate interval. In addition, it is possible to quantify the correlation between the original and ciphertext images in the three directions of neighboring pixels [63].
where x and y are the grayscale values of two neighboring pixels. Table 3 lists the correlation results for the horizontal, vertical, and diagonal directions of Figure 13a-d. From Figure 17 and Table 3, the pixel distribution of the encrypted image is uniform and the correlation coefficient between adjacent pixels is close to 0. Using the "Boat" image of size 256 × 256, the adjacent pixel correlation of different encryption algorithms is tested, and Table 4 lists the test results. The proposed method has less correlation compared to other methods and therefore, the encryption algorithm has better resistance to correlation analysis.  Table 4. Comparison of correlation coefficients of different algorithms.

Differential Attack Analysis
Differential attacks are a popular type of cryptanalysis technique. The attacker first makes small modifications to the original image, such as changing one or more pixel values, and by analyzing the difference between the two encryption results, the attacker may find a way to break the encryption system. However, the proposed algorithm can effectively resist the differential attack as we use a multi-directional diffusion method, which is able to spread small changes in the image to all pixels. Here, we select "Baboon" as the test image, and the pixel values at the coordinates (100,100) are modified, and Figure 18 shows the test results of the differential attack. Figure 18e shows that the generated cipher image is completely different. The pixel change rate (NPCR) and uniform average change intensity (UACI) can also be used to test the ability of the algorithm to resist differential attacks [64]: where M × N represents the size of the image, C 1 and C 2 are the encrypted images obtained by encrypting two images that are only slightly different, and D(i, j) is defined as Figure 18. Differential attack analysis: (a) Original image P 1 ; (b) Image P 2 with one pixel value modified; (c,d) Encryption results C 1 , C 2 using the same key pair (a,b), respectively; (e) Difference between C 1 and C 2 , |C 1 − C 2 |.
Ideally, the values of NPCR and UACI are 99.6094% and 33.4635%, respectively. Table 5 lists the test images using Figure 13a-d as the test images. As can be seen from the table, the test results are very close to the theoretical values. Table 6 compares the experimental results of the proposed encryption algorithm with the existing encryption algorithms for NPCR and UACI, and the selected sample image is a 256 × 256 "Boat" image. Table 6 shows that the test results of the proposed algorithm are closer to the theoretical values compared to the other algorithms.

Robustness Analysis
Image data may encounter the problem of data loss or interference by noise when stored or transmitted. To verify the robustness of the proposed algorithm against data loss and noise interference, Figure 13e-h are selected as test images, and the images are subjected to clipping and noise interference processing before decrypting these images. Figures 19 and 20 show the test results of clipping processing and noise interference, respectively. The results can show that the proposed algorithm can only affect a small number of pixels when decrypting encrypted images that do not change much, indicating that the algorithm is able to resist noise interference attacks and cropping attacks to some extent.

Encryption Speed Analysis
In this section, the encryption speed of the proposed encryption algorithm is analyzed, and 256 × 256 size "Baboon" images were tested several times to obtain the average value. Table 7 shows the results of the proposed algorithm and other algorithms using images of the same size. As this paper uses a complex network to scramble the image, which takes some time, the proposed algorithm needs a longer time to encrypt the image. However, Table 7 shows that the encryption speed of this algorithm is within an acceptable range. Table 7. Encryption speed analysis.

NIST Test
In this section, we use the NIST test program to test the randomness of chaotic sequences and ciphertext images. This test program includes tests to test the randomness of binary sequences of any length. This paper tests the randomness of chaotic sequences and ciphertext images generated by discrete four-dimensional chaotic systems. The results are shown in Table 8. The results show that the chaotic sequence used in the algorithm and the generated ciphertext image have good randomness.

Conclusions
In this study, an image encryption algorithm based on complex network scrambling and multi-directional diffusion is proposed. The algorithm uses the asymmetric homomorphic Paillier algorithm to encrypt the sensitive data for generating chaotic sequences. Firstly, two sets of encrypted information associated with plaintexts are generated from the image information, which are used to generate chaotic sequences in the scrambling and diffusion processes, respectively. The scrambling process uses a complex network model as the core, and uses a combination of pixel-level scrambling and block-level scrambling according to the relationship between the nodes in the network model, which fully scrambles the positions of image pixels. The diffusion process uses multi-directional diffusion for forward, middle spiral, and backward diffusion of the image to obtain the cryptographic image. In the process of diffusion, the pixel values are changed with respect to the neighboring pixels and chaotic sequence element values, and the method allows each pixel information to be diffused to the whole image. Simulation experiments show that the method of image dislocation based on the complex network model is feasible. The proposed algorithm is applicable to both grayscale and color images, and the algorithm is resistant to common attacks and has good security. In the future, we will run more tests to verify the efficiency and security of the proposed algorithm, such as testu01 test. Moreover, in addition to the BA scale-free complex network model used in this study, we will study other types of complex network models and design more efficient encryption algorithms to be applied in the field of security for a variety of media files.

Conflicts of Interest:
The authors declare no conflict of interest.