Image Encryption Algorithm Based on Block Scrambling and Finite State Machine

To better protect the image information, an image encryption algorithm based on block scrambling and finite state machine is proposed. The method uses discrete wavelet transform (DWT) to divide the original image into four frequency bands. Secondly, chaotic sequences and zigzag scanning curve are used to construct a scrambling matrix to scramble the four frequency bands. Then combine the chaotic sequence, DNA coding, and automata to transform the state of the scrambled image. Finally, the key stream is used to diffuse the sequence to improve the security of cipher images further. Experimental results and security analysis show that the proposed encryption scheme can resist various attacks and ensure the secure transmission of images. INDEX TERMS Image encryption; Zigzag scanning curve; DNA coding; Finite State Machine; Discrete wavelet transform;


I. INTRODUCTION
With the development of communication technology, information security has been paid more and more attention. As a carrier carrying a lot of information, it is very important to prevent digital images from being stolen in network transmission. Using image encryption technology can improve the security of digital images in network transmission to some extent. Although text encryption technology has sufficient security, for example, the methods represented by DES [1], AES [2], and SM4 algorithm [3] have been widely used. However, the digital image has a large amount of data, high redundancy, and strong correlation between adjacent pixels, so text encryption technology is not suitable for digital image encryption.
Chaotic systems are characterized by periodicity, ergodic, pseudo-randomness, and high sensitivity to initial conditions and parameters. Since Fridrich [4] proposed a scramblingdiffusion encryption architecture, chaotic systems have received more and more attention. The security of chaotic encryption algorithm is closely related to chaotic system. For example, Logistic map-based encryption algorithm, with simple structure and low computational complexity, has been widely used in early image encryption. Luo [5] proposed an image encryption algorithm that uses two-dimensional discrete wavelet transform and chaotic system to carry out adaptive replacement of pixels. This method enhances encrypted images' security, but Logistic mapping's encryption structure is often relatively simple and has weak resistance to violent attacks and statistical analysis attacks [6]. Zhou [7] proposed a new chaotic system combining two onedimensional chaotic systems and then used the system to encrypt the image. Patidar [8] used Logistic mapping to design a lossless symmetric image encryption algorithm for pixel replacement diffusion structure. However, one-dimensional chaotic systems have the fundamental defects of small keyspace and low chaos. High-dimensional chaotic systems, especially hyperchaotic systems, have many variables and parameters, more complex dynamic characteristics, and larger key space [9], [10], [11]. Therefore, using hyperchaotic system to encrypt images is a better choice. Peng [12] proposed a new image encryption algorithm based on a multidimensional multi-wing hyperchaos system with two Lyapunov exponents greater than zero. In 2015, Guan [13] improved the classical Lorentz system and constructed a Lorentz chaotic system with a relatively large positive Lyapunov index and size by increasing control parameters and changing nonlinear terms. Although the hyperchaotic system has a good effect on image encryption, it still has some shortcomings. Gao [14] proposed an image encryption algorithm based on hyperchaos using pixel-level permutation. The algorithm has the advantage of large key space, but it cannot resist the plaintext and ciphertext attack. Image encryption algorithms based on chaos are generally divided into pixel scrambling and diffusion [15]. CS theory can be regarded as a symmetric cryptosystem. Some scholars combine this theory with chaotic system and propose image encryption algorithm based on CS theory [16], [17]. Chai [18] proposed a color image compression and encryption scheme based on compressed sensing and double random encryption strategy. This algorithm improved its ability to resist KPA and CPA, but the algorithm complexity was high.
Image pixel scrambling mainly uses curves to scan pixels and rearrange them [19], [20], or rearrange pixels through chaotic sequences [21], [22]. The image scrambling method based on chaotic sequence is widely used, and the scrambling effect is better. By sorting the pseudo-random sequence generated by the chaotic system, the image pixels are scrambled by the sorting result. However, sorting of big data often takes a lot of time, and chaotic systems may have chaotic degradation. A single algorithm for encrypting images using chaotic sequences is not reliable, so chaotic systems and other methods are often used for encryption. Unlike the scrambling operation, the diffusion process is generally to perform bit XOR between the encrypted image and the generated chaotic sequence to change the image pixels. The latest trend in image encryption is the application of DNA theory [23]. Based on DNA encryption technology involves two main steps. First, the original image is converted into DNA coding sequence through DNA coding rules. Secondly, the DNA coding sequence created from the chaotic sequence and converted with the original image is used to perform base-pair operations. Zhang [24] proposed a typical DNA encryption method. First, the hyperchaotic system is used to scramble the image pixels, then the scrambled pixels are DNA-encoded and the base-pair exclusive XOR is performed, and finally, the DNA is decoded to convert it into an image. Wu [25] applied it to color image encryption, and diffusion between image pixels is carried out by combining DNA addition, subtraction, and XOR operations. However, these algorithms have some security risks. If an attacker encrypts an image with all pixel values of zeros, it is likely to crack the generated chaotic sequence and thus lead to information leakage.
To solve the above problems, this paper proposes a hyperchaotic image encryption algorithm based on block scrambling and finite automata machine. First, discrete wavelet transform (DWT) is used to divide the original image into four frequency bands: low-frequency part (LL1), horizontal detail (HL1), vertical detail (LH1), and diagonal detail (HH1). Secondly, construct a pixel position scrambling matrix through the zigzag curve and chaotic sequence to scramble the elements of four frequency bands respectively. Four frequency bands after scrambling are subjected to discrete wavelet inverse transform (IDWT), generate the scrambled image, and use the zigzag curve to scramble the image again. Third, DNA encoding rules are used to encode the scrambled image, and the key stream generated by the deterministic state automata (DFA) and hyperchaotic system is used to transform the DNA encoding sequence. Finally, the key stream generated by the chaotic sequence is used to diffuse the image pixels to enhance the security of cipher image. The algorithm complies with the one-time password system and can effectively resist choice known attacks.
We organize the rest of this paper as follows. Section 2 introduces the principle of the method used, Section 3 presents the encryption process of the algorithm in detail, Section 4 conducts an experimental analysis on the algorithm proposed in this paper to prove its security. The conclusion is given in Section 5.

A. NEW FOUR-WING 4D CHAOTIC SYSTEM
Yu [26] modified the three-dimensional (3D) smooth quadratic autonomous chaotic system proposed by Liu [27], and added a linear term to the system to obtain a new 4D smooth quadratic autonomous chaotic system. As shown in equation (1): where a, b, c, d and e are system parameters. x, y and z are state variables and u are nonlinear state feedback controllers. As shown in Figure 1, set the control parameters a = 10, b = 2, c = 12, d =50 and e =5. The phase diagram of the chaotic system is shown in Fig. 1. It can be seen from Fig. 1 that the chaotic attractor of the system can show the four-wing type, whether in the 3D space or the 2D plane, so it is a real four-wing attractor. The chaos system has a large positive Lyapunov index, it can show complex and rich chaotic dynamics behavior.

B. DISCRETE WAVELET TRANSFORM
DWT is a kind of orthogonal wave with very concentrated energy in the time domain. It can display spatial and frequency views simultaneously, so it has the capability of multi-scale analysis. Suppose an image f(x, y) with a size of M × N, its 2D-DWT is defined as: where Φ ( 0 , , ) represents the approximate part of the image, and W Ψ ( , , ) represents the horizontal, vertical and diagonal parts of the image. Φ 0 , , ( , ) represents the scaling function, Ψ , , ( , ) represents the wavelet function. The 2D-IDWT is defined as:

C. DNA CODING
As an important genetic information storage carrier in organisms, DNA has massive parallelism and information density characteristics [28]. Through performing DNA encoding processing on the pixels of the image, the complexity of the encryption algorithm can be enhanced. DNA sequence has four types of nucleic acid bases, namely adenine (A), thymine (T), cytosine (C) and guanine (G). According to the base pair complementation rule, A and T are complementary, G and C are complementary. This complementary rule is similar to binary numbers. For example, 0 and 1 are complementary, so 00 and 11, 01 and 10 are also complementary. Encoding the four bases A, T, C, G to binary 00, 01, 10, 11, there are 24 encoding combinations, but only eight kinds of rules satisfy the Watson-Crick complement rule [29], such as Table 1

A. GENERATE KEYS AND CHAOTIC SEQUENCES
Input the image into the SHA-384 algorithm to generate a 384bit long hash value, it is divided into 48 sequences with a length of 8 bit, and obtain k1, k2, k3, …, k48. The initial iterative parameters of the new four-wing 4D chaotic system x0, y0, z0 and u0 are calculated from equations (5) and (6): Input the generated initial iteration parameters x0, y0, z0 and u0 into four-wing 4D chaotic system iteration 999 + 4 × M × N times, remove the first 999 times, generate chaotic sequences XY, D, U and W are used in the encryption scheme proposed in this paper.

B. SCRAMBLING SCHEME
By scrambling image pixels, the correlation between adjacent pixels can be broken, and differential attacks can be effectively resisted. The Space Filling Curve (SFC) is a continuous scanning method that can scan each pixel accurately and effectively scramble the image pixels. However, it requires multiple repeated scans to achieve a better scrambling effect.
Using the index value generated by the pseudo-random sequence to scramble the image pixels is better, but it takes a long time to sort big data. This paper combines the SFC scrambling method and the chaotic sequence scrambling method to design a block scrambling scheme.
Assuming that the size of the original image matrix P is M × N, First, use DWT to divide the original image into four frequency bands, LL1, HL1, LH1 and HH1. From the generated chaotic sequence XY, let X = XY(1: M/2), Y = XY(M/2 + 1: M/2 + N/2), obtain a chaotic sequence X of length M/2 and a chaotic sequence Y of length N/2 respectively. Then arrange them in descending order to obtain their position index vector IX and vector IY, IX and IY are respectively used as row coordinate index and column coordinate index, and the corresponding positions of row coordinate and column coordinate are combined to generate a scrambling matrix S. The scrambling matrix S is shown in Fig. 2(a). Through the zigzag curve to scan the matrix S to get the scrambling matrix W. Finally, use the scrambling matrix W to scramble the four frequency bands of LL1, HL1, LH1 and HH1, respectively. Perform IDWT transformation on the four frequency bands after scrambling, and use zigzag scanning curve to scrambling the image after inverse transformation to obtain the scrambling image matrix P'. The scrambling process is shown in Fig. 2.

C. STATE TRANSITION
Finite state machines can be divided into deterministic finite automata (DFA) and uncertain finite automata (NFA). Given the current state and input characters, DFA can determine the transition to a certain state, and NFA can transition to multiple states simultaneously. To ensure the algorithm's reversibility, the encryption scheme proposed in this paper uses DFA for state transition. The DFA is defined as: = ( , , , , ) (7) where M represents DFA, Q is a finite state set. Ω is a set of input characters, f is a state transition function, s ⊆ Q is the only initial state, Z ⊆ Q is a final state set.
The state transition of the image can effectively hide the original information of the image. In the state transition scheme proposed in this paper, the pixel value of the input image is encoded by DNA rules (in this paper, use rule 1 is for coding), and the DNA coding sequence SQ is obtained as input for state transition. Define   (8) to process the generated chaotic sequence D to obtain sequence D', and make the value range between 0 and 3 as input characters:

D. DIFFUSION SCHEME
Diffusing the encrypted image pixels can effectively make the original image pixels produce different cipher images when minor changes occur. The first M × N elements of the generated chaotic sequence U and chaotic sequence V are respectively intercepted, and the chaotic sequence U1 and the chaotic sequence V1 are processed according to equations (9) and (10)

E. ENCRYPTION PROCESS
The complete encryption algorithm includes four parts: key generation, block scrambling, state transition and diffusion plan. Steps are as follows: Step 1: Input the original image matrix P of size M × N, and use the key generation system to generate initial parameters x0, y0, z0 and u0. Input the generated initial iteration parameters x0, y0, z0 and u0 into the iterative four-wing 4D chaotic system iteration 999 + 4 × M × N times, remove the first 999 times, and generate four chaotic sequences, denoted as sequence XY, sequence D, sequence U and sequence W respectively.
Step 2: Intercept the chaotic sequence XY to obtain a chaotic sequence X with a length of M/2 and a chaotic sequence Y with a length of N/2 and two chaotic sequences are arranged in descending order, respectively. The position index value of the chaotic sequence X as the row scrambling vector IX and the position index value of the chaotic sequence Y as the column scrambling vector IY to generate a scrambling matrix S. Use the zigzag scan curve to scramble the scrambling matrix S again to obtain the scrambling matrix W. The image matrix P is scrambled according to the scheme in section 3.2 to get the pixel value scrambled matrix P'.
Step 3: Perform DNA coding on the pixel scrambling matrix P' to obtain the DNA coding sequence SQ, and use formula (8) to process the chaotic sequence D to get the sequence D'. The corresponding elements in the sequence SQ and the sequence D' sequentially input into the automaton for state transition, and the state transition sequence SQ' is obtained. Perform DNA decoding on the sequence SQ' and convert it to decimal to get the state transition sequence E; Step The flowchart of the encryption algorithm is shown in Fig. 3.

IV. SAFETY ANALYSIS
This paper uses Matlab 2019a to simulate the encryption algorithm. The computer configuration environment is Windows 10, 8.00 GB RAM, Intel(R) Core(TM) i7-4510 CPU @ 2.00GHz. Fig. 4 shows the original image, cipher image and decrypted image of Lena, Boat, Hill, Peppers. By directly observing the cipher image, no valid information can be identified. To verify the performance of the algorithm, the encryption scheme is analyzed experimentally in this section.

A. KEY SPACE
According to research, even in powerful computer capabilities, if the key space is greater than 2 100 , the encryption scheme cannot be cracked by brute force attacks. Therefore, the key space of the encryption scheme should be large enough to resist brute force attacks. In the encryption scheme proposed in this article, SHA-384 generates the initial parameters of the encryption algorithm x0, y0, z0 and u0. The key space of SHA-384 is 2 192 , and the calculation precision of x0, y0, z0 and u0 is 10 15 , so the total key space is about 10 117 . Therefore, the key space of the encryption scheme proposed in this paper is large enough to resist brute force attacks effectively.

B. DIFFERENTIAL ATTACK ANALYSIS
A good encryption algorithm can be highly sensitive to subtle changes in the original image to resist differential attacks. NPCR and UACI are generally used to measure the resistance to differential attacks. The calculation method is as follows: Author Name: Preparation of Papers for IEEE Access (February 2017) VOLUME XX, 2017 3 Among them, P1 is generated by encrypting the selected original image through the encryption scheme proposed in this article, and P2 is the cipher image generated by encrypting the selected original image by changing a pixel value and then using the same encryption scheme again. If ( , ) = ( , ), ( , ) = 1 , otherwise ( , ) = 0 . Calculate the values of UACI and NPCR using the images provided In the USC-SIPI image database and the encryption scheme proposed in this paper, and compare them with the literature [30], [31], [32], [33]. The results are shown in Table 3 and  3 and table   4 that the encryption scheme proposed in this paper is more resistant to differential attacks.

C. SHANNON ENTROPY AND LOCAL SHANNON ENTROPY
Shannon entropy entropy represents the randomness in the image and the average amount of information carried in the image. Let P be an encrypted image, then the entropy value calculation method of image P is as shown in formula (13): ( ) = −∑ =0 256 ( ) 2 ( ) (13) where mi represents the ith message source and P(mi) is the probability of mi, the ideal entropy for an 8-bit grayscale image is 8. If the cipher image's entropy value is much lower than 8, the original image has the possibility of predictability, and the security of the image encryption algorithm is not high. Table  5 shows the Shannon entropy obtained by encrypting the image using the encryption scheme proposed in this paper. However, there are some shortcomings in calculating the information entropy of the cipher image. For example, the uneven distribution of pixel values may appear in the part of the cipher image. Therefore, calculating the local Shannon entropy (LSE) of cipher image is more effective and more accurate than the global Shannon entropy measure [34]. The calculation method of LSE is: randomly select nonoverlapping image blocks S1, S2, ..., Sk with TB pixels in the test image P. the LSE can be defined as: Obtain the information entropy of each image block according to formula (14), and calculating the average value of the information entropy of these k image blocks is the local information entropy of the image. k represents the number of selected image blocks, and TB is the number of pixels in the selected image block. Set the parameters (k, TB) to (30,1936), and the significance α = 0.05, then the ideal local information entropy is 7.902469317. If the obtained local information entropy is in the interval (7.901901305, 7.903037329), the image is considered to pass the test. Use the encryption algorithm proposed in this paper and the encryption algorithm proposed in [31] and [32]to encrypt the image provided in the USC-SIPI image database and calculate its local information entropy. As shown in Table 6, it can be seen that the encryption algorithm proposed in this paper has a better encryption effect.

D. HISTOGRAM ANALYSIS
Through the histogram of the image, it can be seen intuitively whether the pixel distribution is uniform. Fig.  5 shows the histograms of original images and cipher images. It can be seen that the pixel value of the password image is evenly distributed in the interval [0,255], which is completely different from the pixel value of the original image. The Chi-square test is used to measure the uniformity of the histogram [35], [36]. It is defined as:  (15) Where fi represents the actual pixel frequency of the gray level and gi represent the expected frequency of each gray level. The commonly used significance level is α = 0.05, 0.05 2 = 293.24783, that is, when 2 is lower than this value, it can be considered that the histogram is approximately uniform. The Chi-square test of histogram are shown in Table 7. It can be seen that the algorithm encrypts the original image and can obtains a cipher image with evenly distributed pixels.

E. CORRELATION ANALYSIS
The adjacent pixels of the original image have a high correlation in the horizontal, vertical, and diagonal directions, which is undesirable for encrypted images. An ideal encryption algorithm can reduce the correlation of adjacent pixels and effectively resist statistical attacks. The Pearson Product Moment Correlation Coefficient (PMCC) is used to measure the correlation between adjacent pixels of the original image and the encrypted image. It is defined as: Among them, the E(x) and D(x) to represent the expectation and variance of the variable x respectively, cov(x, y) represents the covariance, and ρxy is the correlation coefficient of adjacent pixels. Randomly select 2000 pairs of pixels, and then use equation (16) to calculate the correlation of the original image and the cipher image of Lena adjacent pixels respectively. It can be seen from Table 6 that after encryption, the cipher image effectively reduces the correlation between adjacent pixels.From Figure 6 shows that the distribution of adjacent pixels in the original Lena image is highly concentrated, indicating that the original image of Lena is highly correlated. The distribution of adjacent pixels in the cipher image of Lena is randomly distributed, indicating that the correlation of Lena cipher image is very low.

F. DATA LOSS ANALYSIS
When images are transmitted over the network, data may be lost due to various reasons. It uses cropping a part of the cipher image to test the ability of cipher image to be restored to the original image when data is lost and analyzes the encryption algorithm's performance against the cropping attack. Fig. 7 shows the decrypted image of the cipher image after it has been cropped. It is obvious that even if the data is lost, the image can still identify the corresponding information after decryption. Therefore, the encryption algorithm proposed in this paper is highly robust to cropping attacks.

G. NOISE ATTACK ANALYSIS
When the image is transmitted on the transmission channel, it is usually affected by noise. Noise attacks on transmitted images are also a way to verify the robustness of encryption algorithms. The noise includes Gaussian noise, uniform noise and salt and pepper noise. In this section, the encryption algorithm is tested by using salt and pepper noise analysis. Fig. 8 shows the experimental results of Lena's plain image and decrypted image with noise intensity of 0.01, 0.05, and 0.1. It can be seen from Fig. 8 that even if the noise intensity reaches 0.1, the decrypted image can still be identified. This shows that the encryption algorithm proposed in this paper can effectively resist noise attacks.

V. CONCLUSION
In this paper, an image encryption scheme based on block scrambling and state transformation is proposed. Firstly, through discrete wavelet transform (DWT) to divide the original image into four frequency bands, and use chaotic sequence and zigzag curve to scramble the image pixels. Secondly, through DNA coding rules to perform DNA coding on the scrambled pixels to obtain DNA coding sequence. Third, use the state machine to convert the state of the DNA coding sequence and then decode the DNA to restore it to decimal. Finally, the key stream generated by the chaotic system is used to diffuse the sequence after the state transition to generate cipher images. Experimental analysis shows that the scheme is highly secure and suitable for image encryption.