An Image Encryption Algorithm Based on Balanced Pixel and Chaotic Map

Image encryption technology has been applied in many fields and is becoming the main way of protecting the image information security. There are also many ways of image encryption. However, the existing encryption algorithms, in order to obtain a better effect of encryption, always need encrypting several times. There is not an effective method to decide the number of encryption times, generally determined by the human eyes. The paper proposes an image encryption algorithm based on chaos and simultaneously proposes a balanced pixel algorithm to determine the times of image encryption.Many simulation experiments have been done including encryption effect and security analysis. Experimental results show that the proposed method is feasible and effective.


Introduction
With the development of technology, encryption and dissemination of digital images developed rapidly.They have been used in many fields such as military, medical, industrial, and multimedia fields [1].In the past years, many encryption modes have been proposed including scan mode method [2], double random phase encoding [3], encoding and iterative random rotation converts vector encoding [4,5], the quad tree coding [6], and coding and chaotic function Kolmogorov flow [7].Due to the inner randomness and initial sensitivity, chaotic encryption has been used widely and developed fast [8].Chaos encryption method is mainly to change the position and value of pixels in the image [9].Among the existing methods, many methods need to be encrypted several times because of the unsatisfied effect [10][11][12][13][14], but there is no effective way to make sure of the exact number of encryption times.Considering this, the paper proposes an encryption algorithm based on chaos and iteration equation and gives the method to determine the number of encryption times.In the algorithm, we present an encryption method based on onedimensional logistic map and change the position and value of pixels sufficiently.By balancing the pixels, the number of encryption times can be decided and the effectiveness of the algorithm through lots of experiments can be verified.2.1.The Chaos Theory.Chaotic system has the characteristic of inner randomness and sensitivity to initial value.The inner randomness is that random uncertainty from the chaotic system happens naturally, not because of the external environmental effect [15].What is more, the sensitivity to initial value means two initial values which are close enough experience a long time along the trajectory and will get two totally different results.

The Chaos Theory and Iterative Equation
Because this algorithm involves the choice of the initial value of seed  (the following part will express seed ), we need it to have two characteristics which are randomness and high sensitivity.So it is necessary to introduce the onedimensional chaos equation logistic function which has these two characteristics.
The one-dimensional chaos equation logistic function is given by where  ∈ [0, 4] and  ∈ [0, 1].Research shows that when  ∈ [0, 1] the function stays in a chaotic condition and shows a state of random uncertainty [16,17].The  is closer to 4,  is closer to even distribution in [0, 1].Therefore, the closer the value of  is to 4, the better is the effect [18].According to the experimental analysis, when  = 3.9999, for two quite close different initial values  0 = 0.675279000 and  0 = 0.675279001, the corresponding logistic sequences are almost the same in 30 times of iteration but are totally different after 30 times.So in this algorithm, select  = 3.9999, and each initial value  0 will be iterated 35 times and then be used and be computed.

Iterative Equation.
In general, adjacent pixels in the image have a strong correlation [19].Therefore, in order to improve the quality of the encrypted image encryption, iterative equation should make the position of each pixel change as far as possible [20], and, in this paper, the encryption process will directly work on each pixel in the original image.The original image can be seen as a two-dimensional matrix of  *  ( rows and  columns).The iterative equation is where  =  − 1 L is the size of the image  0 and  =  *   decreases with each iteration.The seed  is less than .Each loop of the whole algorithm needs a new value.The  is a initial value from  − 1 to 1.The position of pixel can be calculated by memory effect (e.g., the index  read out the size  of the input image and the new position of   after each displacement and ).Therefore, the value of the position of each pixel can be determined after several changes.The significance of this iterative equation is that disrupting the initial position of all of the pixel from 1 to  in the original image.

A Balanced Pixel Algorithm for Image Encryption
This proposed image encryption algorithm combines the chaos theory and iterative equation, converting the position and the value of each pixel of the original image to finish one loop encryption.In order to obtain a better effect of encryption, the algorithm proposes a method in which the number of encryption times can be defined.The flowchart of the algorithm is shown in Figure 1.

The Theory and
Steps of the Encryption.The process of the encryption is completed by the following six steps.
(1) The original image is with  0 , a two-dimensional matrix of  rows and  columns; transform  0 into a one-dimensional sequence The (2) Given an initial value of  0 ,  = 3.9999, according to the chaotic equation ( 1) get a random sequence about   .As mentioned, logistic function will show better avalanche state after 30 times of iteration, so in this algorithm we use the data after 35 iterations, that is, to use the data from the beginning of  35 .Since the sequence   is a set of decimals between 0 and 1, while algorithm needs integer, so we expend each of the decimals we get 10 7 times and then get the last two digits as the value of .Moreover, we also have to think about the value which is from the 35th of the sequence; thus,  is shown as where  represents the number of cycling times of the whole algorithm.
(4) Determine  1 , which is a sequence from an onedimensional   0 , shown as (5): (5) Determine  2 , which is an algebraic equation got from   about , shown as (6) Determine  3 , which is a sequence got from the XOR operation between  1 and  2 , as 1 ,  2 , and  3 are a loop.Each loop will get  3 and this  3 will be the new  1 of the next loop; then, according to (4) a new  to continue the next time of cycling is given.

Determination of the Number of Encrypting Times.
In order to get a good effect, we need to repeat the six steps above several times (the six steps are the time of cycle of the encryption and also the main process of the algorithm).Each time of the cycling will get different effect of the encrypted image.To achieve the most effective encrypted image, an analysis of the number of cycling times  is needed; then, the optimal value of the images with different size is given.
R is related to  1 and  2 ,  1 is determined by key space,  2 can be given by experimental analysis, and what follows in the passage will be the determination of R in detail.
According to today's computing speed, statistical analysis shows that key space of the encryption system that is larger than 2 256 can resist brute force attacks.In this algorithm, each time of cycling will give an initial  (e.g.,  = 1) and generate L different codes.Therefore, as the growth of the cycling number R, the total number of keys can be shown as   .To satisfy the relationship   ≥ 2 256 and avoid brute force, the minimum of R is defined as As can be seen from the equation above,  min is a decreasing sequence, with the size of the image increasing, and the number of cycle times we need is decreasing.By (8) it can be calculated that  1 is decreasing with the increasing size of the image.Table 1 shows the corresponding  1 for different image size.
1 is a limitation on key space, and to finalize R, a more important indicator is needed, that is,  2 balancing the image pixel value.

Determination of 𝑅 2 .
Balance pixels, as the name suggests, are the average of pixels in an image.Grayscale images have 256 gray levels from 0 to 255.Each one is made up of several pixels of any level from 0 to 255.These 256 gray levels which are not necessary all appear in one image, and there is not a fixed value of them, so they are dispensable and can be more or less.A good encryption algorithm is to make the number of each encrypted image pixel be distributed evenly.Assuming an  *  image  0 needs to be encrypted, then the image has a total of  =  *  pixels.First calculating that the pixel value of 0 has ℎ 0 and pixel value of 1 has ℎ 1 , so the pixel value of 255 has ℎ 255 .Here ℎ  stands for the number of pixel values of n,  ∈ [0, 255], and  is an integer.Evaluate a good encryption algorithm; a standard is to balance pixel as far as possible.Therefore, the experimental will give statistics about the balance of pixel after each time of cycle.Here the balance means that 256 gray levels are uniformly distributed in the whole image.Ideally there are Do quotient operation between H and  0 and get   which is the rate of deviation between the actual and ideal situations of each pixel as shown in Thus the total rate of deviation is the sum of these 256   recorded as K and is as shown in Then get the average rate of deviation  which is shown in What we need to do is getting a  after each time of cycle and make it as low as possible, and when it achieves the lowest point or a value that we can accept, stop cycling and get  2 .Through comparing to  1 ,  2 should be selected larger than  1 , and smaller than .This  2 is also the number of cycle times of the whole encryption algorithm.

Experimental Analysis
4.1.Analysis on Encryption Effectiveness.This section will make specific experiment on algorithm and give the effectiveness analysis.Take an image of the size 512 * 512 as an example and give the experimental process.The original image is shown as in Figure 2. When the file is a color image, the system will convert the image to grayscale automatically.The length and the width shown in the picture are just the size of the image, as this figure is 512 * 512.
Start to encrypt; you can fill in the number of cycles needed.As can be seen from Table 1, the smallest possible value of  1 is 15 for the 512 * 512 size image.To facilitate the observation of the image trend, input 25 times directly.Then press the button encrypt; program begins to run and several seconds later, the line chart is as shown in Figure 3(a) and the encrypted image is as shown in Figure 3(b).
Figure 3 is the encrypted image of 25 times of cycle, which obviously have not achieved the desired effect, while it can be seen from the line chart that the lowest points of the plotline are the 7th, 15th, and 23rd times of cycle.To satisfy the condition not less than  1 , reset the number of cycle times to 15, given the line chart and the encrypted image as shown in Figure 4.This time experiment gets a good effective encrypted image.
Several experiments statistical analysis can draw a conclusion that images of different sizes require different ideal numbers of cycle times shown in Table 2.
When given the size of an image, you can input the number of the cycle times directly according to Table 2. Also the cycle times can be calculated.First get the restriction of  1 and then input a number which is larger than  1 as the cycle time (usually the number is larger than  1 10); observe the line chart that appeared and finally take the lowest point as the number of cycle times.
Go on taking an image of size 100 * 100 as the original figure.Based on the conclusion above, you can determine directly that it needs 23 times of cycling.The original and   encrypted images are shown as in Figure 5 and the chart line is shown as in Figure 6.It displays that the lowest points are 7th, 15th, and 23rd points and the highest point is 16th point.Here the encrypted image and line chart of 16 times of cycling are shown as in Figure 7.It can be seen that the result is not that ideal but uneven.

Analysis on Key Sensitivity.
The experiments above can prove the effectiveness and practicality of the algorithm; a good algorithm should also have strong security to resist brute attack.This section will give the analysis on key sensitivity.The same 512 * 512 picture of Lena is given as the original image.The initial value  0 = 0.642235000.The original image and encrypted image are as shown in Figures 0.0046 0.0043 0.0049 Reference [22] 0.0059 −0.0052 0.0190 8(a) and 8(b).When  0 is changed to   0 = 0.642235001, the encrypted image cannot be decrypted successfully, which is shown in Figure 8(c).It shows that the algorithm has strong sensitivity to initial value.

Analysis on Correlation.
The correlation coefficient is the evaluation criterion for the degree of linear correlation between two random variables.We randomly selected 2,500 pairs of adjacent pixels (in vertical, horizontal, and diagonal directions) from both the original and encrypted images of Lena and calculated the correlation coefficient for each pair of adjacent pixels according to (14).Table 3 shows the results of correlation coefficients of two adjacent pixels, which are compared with the results in [21,22].The results indicate that the correlation of two adjacent pixels of the plain image is significant.Therefore, the encryption effect of this algorithm is pretty good.Therefore, the encryption effect of this algorithm is pretty good:

Conclusion
This algorithm uses a chaos function acting on an iterative equation and then combines with XOR operation to encrypt images.The chaos function improves sensitivity to initial value, the iterative equation plays a role of changing the position, and the XOR operation transforms the value of pixels.Such a combination can enhance the effectiveness and security of the encryption algorithm.In addition, this algorithm has a characteristic of cycling the main encryption process many times to achieve an optimal encryption effect.
Through several experiments, it can also be proved that the encryption speed is also relatively fast.An ordinary size of the image can be encrypted completely in a few seconds.
To summarize the algorithm has the features of being fast, efficient, safe, and convenient.Certainly, to encrypt faster and more sophisticatedly, improvements on chaos and iterative equation can be made.

Figure 1 :
Figure 1: The flowchart of the algorithm.

Figure 3 :
Figure 3: The line chart and the encrypted image.

Figure 4 :
Figure 4: The line chart and the encrypted image.

Figure 5 :
Figure 5: The original image and encrypted image.

Figure 7 :
Figure 7: The line chart and the encrypted image.

Figure 8 :
Figure 8: The effect of encrypted and decrypted images.

Table 1 :
The relationship between the image size and  1 .

Table 2 :
Ideal number of cycling times.

Table 3 :
The comparison of the correlation coefficients of Lena's images.