# Chaotic Cryptosystem for Selective Encryption of Faces in Photographs

Authors: Jorge Aguilar Santiago; Octavio Flores Siordia; José T. Guillen Bonilla; Juan C. Estrada Gutiérrez; María G. González Novoa; Maricela Jiménez Rodríguez
Journal: Security and Communication Networks
 (2020)

---

## Abstract

In this article, a safe communication system is proposed that implements one or more portable devices denominated SBC (single-board computers), with which photographs are taken and that later utilizes the OpenCV Library for the detection and identification of the faces that appear in them. Subsequently, it consults the information in a stored database, whether locally in SBC or in a remote server, to verify that the faces should be coded, and it encrypts these, implementing a new cryptosystem that executes mathematical models to generate chaotic orbits, one of which is used for application on two occasions the technique of diffusion with the purpose of carrying out a small change in one of the pixels of the image, generating very different cryptograms. In addition, in order to make a safer system, it implements other chaotic orbits during the technique of confusion. With the purpose of verifying the robustness of the encryption algorithm, a statistical analysis is performed employing histograms, horizontal, vertical, and diagonal correlation diagrams, entropy, number of pixel change rate (NPCR), unified average change intensity (UACI), sensitivity of the key, encryption quality analysis, and the avalanche effect. The cryptosystem is very robust in that it generates highly disordered cryptograms, supports differential attacks, and in addition is highly sensitive to changes in the pixels as well as in the encrypted keys.


---

## Body

## 1. Introduction

Facial recognition is very important today due to its application in security, surveillance systems, forensic analyses, etc. Therefore, it is important to conduct investigation in this area, as well as in research in which a system is developed to detect the drowsiness of a conductor, considering its positions, the form around the eye, and whether the head is inclined [1]. These authors also carried out a balance between image similarities and differences in order to detect human faces even when they had noise or facial expressions and different poses [2]. However, facial recognition can also be utilized to generate damage; thus, it is necessary permit the protection of identity by means of encryption systems, which can be employed to code photographs completely, although it is most recommendable to perform selective encryption, whether on the borders or using facial detection because this considerably reduces the system’s time and resources [3, 4]. Shakir et al. detected faces in the images, considering a database that contains information of different parts of the skin [5]. Rachmawati et al. elaborated a cryptosystem for Android that employs cryptography [6]. Vela Medina et al. carried out an embedded system that utilizes an intelligent camera, in addition to algorithms to detect and recognize faces in a video surveillance system that performs the capture and storage of the images and subsequently, it sends a message to inform the user [7]. Rodrigues et al. coded the human face in a video sequence using AES and VLC (variable length coding); these authors detected the skin, but the method does not render the faces totally unrecognizable [3]. Khashan et al. implemented border and facial detection methods utilizing OpenCV and employing the Blowfish algorithm for encryption [4]. Also, in the work developed by Hong and Jung, the authors implemented a partial encryption method that only codes the facial region in images and videos; they used a Gaussian skin-color model for detection and, in addition, DES (data encryption standard) and AES (advanced encryption standard) for encryption [8]. Gerhardt et al. selectively encrypted faces in videos using Sophisticated High-speed Object Recognition Engine (SHORE) for the detection and use of AES-256 [9]. In another research, these authors encrypted facial regions by applying multilayer encoding on images in the frequency domain, but they do not divide the human region and it may also encrypt clothing [10]. Also, they encrypted important objects in the image that are detected with the machine learning technique through the OpenCV Library and employed an algorithm called RNS to encrypt these, increasing the encryption speed but losing the context of the original image [11]. They extract all of the faces that appear in the videos using high-speed support functions with the OpenCV Library, implementing NewHope, public, private, and SHA-3 keys on order to encrypt; faces are encoded in parallel using GPU [12]. Sardar et al. use the tree-structured part model (TSPM) to extract the region of the face; for training, they employ sparse representation coding (SRC), coordinate descent (CD) and block coordinate descent (BCD), and the SVM classifier. They also implement a variant of BioHashing to generate face code from the characteristic vector. Then, to provide greater security, they adapt the RSA algorithm [13]. Asgari-Chenaghlu et al. use YoloV3 to automatically detect objects or the human body of the ROI delimiter and utilize a cryptosystem based on the chaotic sine map and logistic map systems. They only detect objects of interest and encode them [14]. Additionally, investigations have also been developed in which the properties of the chaotic systems are taken advantage of, such as the high sensitivity of the initial conditions as well as of the parameters. This is due to that the latter are excellent candidates for the development of cryptographic systems, such as those in which they detect the face in order to later extract regions of the body and encrypt them [15]. Wen et al. selectively encrypt objectives in infrared images employing logistic chaotic maps and sine [16]. These authors also developed a selective facial encryption system in gray tones utilizing the tent chaotic map [17]. Prabhavathi et al. selectively encrypt regions of interest in medical images utilizing multiple chaotic systems [18]. In addition to the latter, discrete chaotic systems have also been taken advantage of to encrypt images [19–22]. Ayoup et al. divide the image into blocks and, according to the entropy involved, determine which of these to code using pseudorandomized numbers (PRNs), Arnold’s cat map, and AES [23]. The proposed communication system performs selective facial detection, identification, and encryption, encoding only the object of interest and leaving the environment visible, unlike general encryption, which hides everything. Thus, encryption time and resources are reduced compared to the encryption of a full image and increases the security of people who do not want their faces to be visible when others post their photographs. It is also useful for protecting identity in the news when someone is presented who is under criminal proceedings. It allows protecting the identity of minors when adults wish to publish photographs, and it can also be used in closed-circuit video surveillance networks or in photographs published through social media and communication. Our system, in contrast to those described in the current research, can selectively encode only faces indicated in a database or manually when the face cannot be identified. In addition, there is an encryption algorithm that implements novel confusion and diffusion techniques; these allow the system to be robust on confronting different attacks, and especially that of the avalanche effect, which not all cryptosystems approve.The remainder of this article is organized as follows: in Section2, the mathematical models are explained that are implemented during encryption. Section 3 details the functioning and the stages carried out by the communications system, while the results and the tests conducted on the cryptogram are presented in Section 4. Finally, Section 5 presents the conclusions of this investigation.


## 2. Mathematical Models

### 2.1. Rössler  Oscillator

This comprises a simultaneous system of 3 differential equations:(1)dxdt=−y+z,dydt=x+ay,dzdt=b+zx−c,where x,y,andz are the dependent variables of time, whilea,b, andc are the parameters. In the system, the third equation makes this possess nonlinear chaotic behavior [24].


## 2.1. Rössler  Oscillator

This comprises a simultaneous system of 3 differential equations:(1)dxdt=−y+z,dydt=x+ay,dzdt=b+zx−c,where x,y,andz are the dependent variables of time, whilea,b, andc are the parameters. In the system, the third equation makes this possess nonlinear chaotic behavior [24].


## 3. Communication System

This comprises a server and can have one or more portable devices through which recognition can be performed with the Open Computer Vision (OpenCV) Library or, in a particular case, code selected faces in photographs as well as in videos; this is due to that the latter are composed of a series of photograms, in which it is possible to detect the faces and to code them later.Figure1 shows the general procedure that the communication system carries out, which includes the following stages:(1)
Registration and training(2)
Face detection(3)
Selective encryption(4)
Cryptogram generationFigure 1
Stages of selective facial encryption.


### 3.1. Registration and Training

First, it is necessary to carry out registration and training with the information of all persons who are to be added to the database, for which the process is performed that is depicted in Figure2.Figure 2
Data registration and training phase.(1)
Register the data: the information is stored in a database performed in SQLite3 on the persons involved, such as the following: ID, name, and, in addition, it is indicated whether it is necessary to code the face once it is detected in the photographs. This information can be stored in three ways:(i)
In a base of local data (limited), stored in the portable device.(ii)
Base of complete data, located in a remote server.(iii)
Conduct the capture of the data of both databases, that is, local and remote.(2)
Training: this is carried out with the OpenCV Library. In this process, different photographs are taken of the person, whether from the SBC or with another camera, and the process continues with the generation of the vector characteristic of each face, which is stored in the registry of its ID in the database.


### 3.2. Face Detection

First, the photograph is captured or stored in the single-board computer (SBC). Subsequently, the OpenCV Library is utilized to locate the faces, which are identified and marked with a square, as can be observed in Figure3.Figure 3
Face detection phase.


### 3.3. Selective Encryption

The system permits manual selection through an interface, in which the face is selected and encrypted, as can be observed in Figure4.Figure 4
Manual facial encryption.Also, encryption can be automatic, by means of a communications schema, which performs recognition, taking information locally, remotely, or considering both databases, as demonstrated in Figure5.Figure 5
Techniques for facial recognition.(i)
Local: the faces extracted from the photograph are compared with the information that was stored in the database of the local device (SBC) during the training phase, in order to identify them and to determine whether it is necessary to code them.(ii)
Remote: it is verified whether there exists information on the face in the local database of the device. In the case of there not being information, optimized encryption is conducted with the purpose of this being more agile, but safe for transmission via Internet; that is, the diffusion technique of the algorithm is employed only for encryption. Later, this is sent to the remote server to carry out the search in its database; in the case of finding it, a signal is returned to the source, indicating that faces should be encrypted.


### 3.4. Generation of the Cryptogram

Once a certain face is detected that should be coded according to the information stored in the database, the cryptogram should be generated utilizing the following procedure.


#### 3.4.1. Algorithm to Encrypt

The encryption algorithm can work with any chaotic mathematical model one wishes to employ, as long as the required number of orbits is generated. The Rössler oscillator is implemented because it generates three complex chaotic sequences, is highly sensitive to initial conditions and system parameters, and uses six keys each time it is resolved, generating a very wide key space.Keys(i)
Diffusionx10,y10,z10,a1,b1,c1: values corresponding to the initial conditions and parameters used to apply Diffusion I, when the chaotic system of the Rössler oscillator is resolved (equation (1)). x30,y30,z30,a3,b3,c3: keys utilized to apply Diffusion II.startdif1,stardif2: the keys necessary in the two diffusion processes, which are utilized as initial position and that can be taken between 1 and L; where L=width_image ∗ height_image ∗3.(ii)
Confusionx20,y20,z20,a2,b2,c2: these initial conditions and parameters are also utilized to resolve the Rössler oscillator (equation (1)).keyconf: initial position between 0 and 5.keyconf2: value between 0 and 16777215, which is employed to select a position.Apply Diffusion IEach face is broken down into the pixels comprising it, and later into their 3 subpixels (red, green, blue (RGB)), which have a value between 0 and 255.Step 1: store in a vector of lengthL, called image, the subpixels of the face:(2)image=R1,G1,B1,…,Rn,Gn,Bn.Step 2: create a vector calleddif1 of size L.Step 3: resolveR times the system of equation (1), implementing the encryption keys of x10,y10,z10,a1,b1,c1; where R = width_image ∗ height_image. The values generated of x1R,y1R,z1R are stored in a vector called chaos of length L=3∗R:(3)chaos=x11,y11,z11,…,x1R,y1R,z1R.Step 4: assign, to the variableLoc, the value of the key startdif1.Step 5: take a value ofimage and assign it to location Loc of vector dif1, as can be observed in Figure 6:(4)dif1Loc=imagei.Step 6: take the absolute value of an element of the vectorchaosj, later adding to it dif1Loc; finally, the result is rounded off and is assigned to the variable inc:(5)inc=roundabschaosj+dif1Loc.Step 7: verify ifchaosj≥0, then(6)Loc=Loc+incseq=1.Step 8: else, ifchaosj<0, then(7)Loc=Loc−incseq=0.Step 9: verify ifdif1Loc is empty, assigning to it an element of image; else, go to Step 10 (see Figure 7).Step 10: verify ifdif1Loc is not empty and seq=0, Loc is decreasing, until finding a formerly empty location; contrariwise, if seq=1, Loc increases. On localizing an empty position, assign to it the element of image. This procedure is presented in Figure 8.(8)dif1Loc=imagei.Step 11: repeat Steps 6 through 10, until arranging all of the subpixels of the vectorimage in dif1.Figure 6
Assign a value ofimage to another position of vector dif1.Figure 7
Assign a value ofimage to an empty position of vector dif1.Figure 8
Locate an empty location indif1 to store the data.Diffusion I algorithm is shown in Algorithm1.Algorithm 1: Diffusion I.
Input:vector image,stardif1,x10,y10,z10,a1,b1,c1Output:vector dif1(1)
L=subpixels of image(2)
R=L/3(3)
i=1(4)
forj=1toRdo(5)
Chaosj=Solve Equation1with RungeKutta−4and keysx10,y10,z10,a1,b1,c1.(6)
end(7)
Loc=stardif1(8)
dif1Loc=imagei(9)
i=i+1(10)
forj=1toLdo(11)inc=roundchaosj+dif1Loc(12)
ifchaosj≥0then(13)
Loc=Loc+inc(14)seq=1(15)end(16)
elseifchaosj<0then(17)
Loc=Loc−inc(18)
seq=0(19)
end(20)ifdif1Locis NULLthen(21)dif1Loc=imagei(22)
end(23)elseifdif1Locis not NULLandseq=0then(24)
whiledif1Locis not NULL(25)
Loc=Loc−1(26)end(27)
dif1Loc=imagei(28)
end(29)
elseifdif1Locis not NULLandseq=1then(30)
whiledif1Locis not NULL(31)
Loc=Loc+1(32)end(33)
dif1Loc=imagei(34)end(35)i=i+1(36)
endConfusionStep 1: convert, to their value in pixel [0, 16777215], the elements ofdif1 and store them in a pix_image vector of R length:(9)pix_image=P1,P2,P3,…,PR.Step 2: resolveR times the system of equation (1) using encryption keys x20,y20,z20,a2,b2,c2, yielding as a result three orbits:(10)orbx=x21,x22,…,x2R,orby=y21,y22,…,y2R,orbz=z21,z22,…,z2R.Step 3: generate integer values between 0 and 16777215, dividing an element oforbx between the absolute value of the highest number of the vector, subsequently multiplying this by 16777215. The result is rounded off and the value of orbxi is substituted.(11)orbxi=roundorbxi/absHighestorbx∗16777215.Step 4: convert, to a 6-digit hexadecimal, each element ofpix_image, as shown in Figure 9.Confusion algorithm is shown in Algorithm2.Algorithm 2: Confusion.
Input:vector dif1,x20,y20,z20,a2,b2,c2,keyconf[0, 5], keyconf2 [0, 16777215].Output : vector conf(1)
pix_image=convert dif1to its values in pixels.(2)
R=length of pix_image.(3)
fori=1toRdo(4)
orbxi,orbyi,orbzi=Solve Equation1with RungeKutta−4and keysx20,y20,z20,a2,b2,c2.(5)
end(6)
fori=1toRdo(7)
orbxi=roundorbxi/highestorbx∗16777215(8)
end(9)
pix_image=convert to hexadecimalpix_image(10)
fori=1toRdo(11)
rotation=store6decimals of orbyi(12)pix_imagei=apply diffusionIpseudocode with keyconf,rotation and pix_imagei(13)
pix_imagei=convert to decimalpix_imagei(14)
end(15)
before=pix_image1(16)
cipher1=pix_image1XOR keyconf2(17)
fori=2toRdo(18)
cipher [i] = beforeXOR pix_image[i](19)
before=pix_imagei(20)
end(21)
fori=1toRdo(22)confi=orbxiXOR cipheri(23)
endFigure 9
Convert from decimal to hexadecimal.Step 5: store, inrotation, the first 6 decimals of an element of the vector orby, which will be utilized to indicate the number of times that each hexadecimal digit moves among the elements stored in the vector pix_image.Step 6: apply the algorithm of diffusion I to an element ofpix_image, taking into account the key keyconf and the positions indicated in rotation; later this is converted into a decimal, as can be observed in Figure 10.Step 7: repeat Steps 5 and 6 until applying the diffusion I algorithm to all elements ofpix_image.Step 8: store in the variablebefore an element of pix_image, later applying XOR between pix_imagei and keyconf2. Repeat this procedure to encrypt all elements of pix_image. However, from the second iteration, the value stored in before is used to apply XOR with the pix_image elements instead of keyconf2. The results will be stored in vector cipher. In this step, each pixel value is taken into account in order to apply confusion; thus, a modification in one of these will generate cascade changes in the cryptogram. This process is exhibited graphically in Figure 11.Step 9: apply XOR between vectorscipher and orbx, with the result stored in vector conf. The procedure is shown in Figure 12.Diffusion II. Take vectorconf and apply the procedure indicated in Diffusion I, but with keys x30,y30,z30,a3,b3,c3 and stardif2; in the end, the cryptogram is generated.Figure 10
Change the value of the pixel.Figure 11
Apply XOR to substitute the elements ofpix_image.Figure 12
Apply XOR betweencipher and orbx.


#### 3.4.2. Algorithm for Decryption

Eliminate Diffusion IIStep 1: store the cryptogram’s subpixel vectorimage, which has a length of L=Rn+Gn+Bn.(12)image=R1,G1,B1,…,Rn,Gn,Bn.Step 2: create a vector calledconf of sizeL.Step 3: resolveR times the system of equation (1), with encryption keys x30,y30,z30,a3,b3,c3. The values generated of x3R,y3R,z3R are stored in a vector denominated chaos:(13)chaos=x31,y31,z31,…,x3R,y3R,z3R.Step 4: assign, to the variableLoc, the value of key startdif2.Step 5: take, from locationLoc in vector image, the value and place it in conf. This procedure is shown in Figure 13.(14)confi=imageLoc.Step 6: take the absolute value of an element of the vectorchaosj, later adding it to a value of confi, rounded off the result and assigning it to inc:(15)inc=roundabschaosj+confi.Step 7: verify ifchaosj≥0, then(16)Loc=Loc+incseq=1.Step 8: contrariwise, ifchaosj<0, then(17)Loc=Loc−incseq=0.Step 9: verify ifImageLoc has a value, assigning it to the next position in conf; contrariwise, proceed to Step 10 (see Figure 14).Step 10: in the case ofImageLoc being empty and seq=0, Loc will decrease; contrariwise, if seq=1, Loc increases. This procedure is carried out until finding a value and assigning it to conf (see Figure 15).(18)confi=imageLoc.Step 11: repeat Steps 6–10 until arranging allImage elements in conf.Eliminate diffusion II algorithm is shown in Algorithm3.Algorithm 3: Eliminate diffusion II.
Input:vector cryptogram,stardif2,x30,y30,z30,a3,b3,c3.Output:vector conf(1)
image=convert cryptogram to its values in subpixels.(2)
L=subpixels of image(3)
R=L/3(4)
i = 1(5)
forj=1toRdo(6)
Chaosj=Solve Equation1with RungeKutta−4and keysx30,y30,z30,a3,b3,c3.(7)
end(8)
Loc=stardif2(9)
confi=imageLoc(10)
i=i+1(11)
forj=1toLdo(11)
inc=roundchaosj+confi(12)ifchaosj≥0then(13)Loc=Loc+inc(14)seq=1(15)
end(16)
elseifchaosj<0then(17)Loc=Loc−inc(18)seq=0(19)
end(20)
ifimageLocis not NULLthen(21)confi=imageLoc(22)end(23)
elseifimageLocis NULLandseq=0then(24)whileimageLocis NULL(25)Loc=Loc−1(26)
end(27)
confi=imageLoc(28)
end(29)
elseifimageLocis NULLandseq=1then(30)
whileimageLocis NULL(31)Loc=Loc+1(32)end(33)
confi=imageLoc(34)end(35)
i=i+1(36)
endEliminate ConfusionStep 1: convert the elements of vectorconf from subpixels into pixels:(19)conf=P1,P2,P3,…,PR.Step 2: createorbx,orby,orbzStep2,confusion.Step 3: again, generate whole values between 0 and 16777215 (Step 3, confusion):(20)orbxi=roundorbxiabsHighestorbx∗16777215.Step 4: apply XOR betweenconf and orbx, with the result stored in cipher, as can be observed in Figure 16.Step 5: assign, to variablebefore and to vector pix_image, the result of applying XOR between the first element of cipher and keyconf2. Repeat this procedure to decrypt the entire vector cipher. But, from the second iteration, the value stored in before is utilized to apply XOR with the elements after cipher, instead of keyconf2, as can be observed in Figure 17.Step 6: regeneraterotation, taking the 6 first decimals of an element of vector orby.Step 7: implement the algorithm to eliminate diffusion II, taking an element ofpix_image, the key keyconf and the positions indicated in rotation; later, convert this into a decimal, as can be observed in Figure 18.Step 8: repeat Steps 6 and 7 until rearranging each element of vectorpix_image.Step 9: convertpix_image from a hexadecimal into a decimal.Eliminate confusion algorithm is shown in Algorithm4.Algorithm 4: Eliminate confusion.
Input:vector conf,x20,y20,z20,a2,b2,c2,keyconf[0, 5], keyconf2 [0, 16777215].Output:vector pix_image(1)
conf=convert conf to its values in pixels.(2)
R=pixels of conf.(3)
fori=1toRdo(4)
orbxi,orbyi,orbzi=Solve Equation1with RungeKutta−4and keysx20,y20,z20,a2,b2,c2.(5)
end(6)
fori=1toRdo(7)
orbxi=roundorbxi/highestorbx∗16777215(8)
end(9)
fori=1toRdo(10)
cipheri=orbxiXOR confi(11)
end(12)
before=cipher1XOR keyconf2(13)
pix_image1=before(14)
fori=2toRdo(15)
pix_image [i] = beforeXOR cipheri(16)before=pix_imagei(17)
end(18)
pix_image=convert to hexadecimalpix_image(19)
fori=1toRdo(20)rotation=store6decimals of orbyi(21)
pix_imagei=apply eliminate diffusion II with keyconf,rotation  and pix_imagei(22)pix_imagei=convert to decimalpix_imagei(23)
endEliminate Diffusion I. Take vectorpix_image and apply the procedure indicated in Eliminate Diffusion II, but with keys x10,y10,z10,a1,b1,c1,and stardif1; finally, the original image is recovered.Figure 13
Place the value ofimage in its original position in vector.Figure 14
Assign the value of the vectorimage in position Loc in vector conf.Figure 15
Localize the following site with a datum in the vectorimage.Figure 16
ApplyXOR between confand orbx.Figure 17
Restore the vectorpix_image, reverting XOR to cascade.Figure 18
Restore the value of the pixel.


## 3.1. Registration and Training

First, it is necessary to carry out registration and training with the information of all persons who are to be added to the database, for which the process is performed that is depicted in Figure2.Figure 2
Data registration and training phase.(1)
Register the data: the information is stored in a database performed in SQLite3 on the persons involved, such as the following: ID, name, and, in addition, it is indicated whether it is necessary to code the face once it is detected in the photographs. This information can be stored in three ways:(i)
In a base of local data (limited), stored in the portable device.(ii)
Base of complete data, located in a remote server.(iii)
Conduct the capture of the data of both databases, that is, local and remote.(2)
Training: this is carried out with the OpenCV Library. In this process, different photographs are taken of the person, whether from the SBC or with another camera, and the process continues with the generation of the vector characteristic of each face, which is stored in the registry of its ID in the database.


## 3.2. Face Detection

First, the photograph is captured or stored in the single-board computer (SBC). Subsequently, the OpenCV Library is utilized to locate the faces, which are identified and marked with a square, as can be observed in Figure3.Figure 3
Face detection phase.


## 3.3. Selective Encryption

The system permits manual selection through an interface, in which the face is selected and encrypted, as can be observed in Figure4.Figure 4
Manual facial encryption.Also, encryption can be automatic, by means of a communications schema, which performs recognition, taking information locally, remotely, or considering both databases, as demonstrated in Figure5.Figure 5
Techniques for facial recognition.(i)
Local: the faces extracted from the photograph are compared with the information that was stored in the database of the local device (SBC) during the training phase, in order to identify them and to determine whether it is necessary to code them.(ii)
Remote: it is verified whether there exists information on the face in the local database of the device. In the case of there not being information, optimized encryption is conducted with the purpose of this being more agile, but safe for transmission via Internet; that is, the diffusion technique of the algorithm is employed only for encryption. Later, this is sent to the remote server to carry out the search in its database; in the case of finding it, a signal is returned to the source, indicating that faces should be encrypted.


## 3.4. Generation of the Cryptogram

Once a certain face is detected that should be coded according to the information stored in the database, the cryptogram should be generated utilizing the following procedure.


### 3.4.1. Algorithm to Encrypt

The encryption algorithm can work with any chaotic mathematical model one wishes to employ, as long as the required number of orbits is generated. The Rössler oscillator is implemented because it generates three complex chaotic sequences, is highly sensitive to initial conditions and system parameters, and uses six keys each time it is resolved, generating a very wide key space.Keys(i)
Diffusionx10,y10,z10,a1,b1,c1: values corresponding to the initial conditions and parameters used to apply Diffusion I, when the chaotic system of the Rössler oscillator is resolved (equation (1)). x30,y30,z30,a3,b3,c3: keys utilized to apply Diffusion II.startdif1,stardif2: the keys necessary in the two diffusion processes, which are utilized as initial position and that can be taken between 1 and L; where L=width_image ∗ height_image ∗3.(ii)
Confusionx20,y20,z20,a2,b2,c2: these initial conditions and parameters are also utilized to resolve the Rössler oscillator (equation (1)).keyconf: initial position between 0 and 5.keyconf2: value between 0 and 16777215, which is employed to select a position.Apply Diffusion IEach face is broken down into the pixels comprising it, and later into their 3 subpixels (red, green, blue (RGB)), which have a value between 0 and 255.Step 1: store in a vector of lengthL, called image, the subpixels of the face:(2)image=R1,G1,B1,…,Rn,Gn,Bn.Step 2: create a vector calleddif1 of size L.Step 3: resolveR times the system of equation (1), implementing the encryption keys of x10,y10,z10,a1,b1,c1; where R = width_image ∗ height_image. The values generated of x1R,y1R,z1R are stored in a vector called chaos of length L=3∗R:(3)chaos=x11,y11,z11,…,x1R,y1R,z1R.Step 4: assign, to the variableLoc, the value of the key startdif1.Step 5: take a value ofimage and assign it to location Loc of vector dif1, as can be observed in Figure 6:(4)dif1Loc=imagei.Step 6: take the absolute value of an element of the vectorchaosj, later adding to it dif1Loc; finally, the result is rounded off and is assigned to the variable inc:(5)inc=roundabschaosj+dif1Loc.Step 7: verify ifchaosj≥0, then(6)Loc=Loc+incseq=1.Step 8: else, ifchaosj<0, then(7)Loc=Loc−incseq=0.Step 9: verify ifdif1Loc is empty, assigning to it an element of image; else, go to Step 10 (see Figure 7).Step 10: verify ifdif1Loc is not empty and seq=0, Loc is decreasing, until finding a formerly empty location; contrariwise, if seq=1, Loc increases. On localizing an empty position, assign to it the element of image. This procedure is presented in Figure 8.(8)dif1Loc=imagei.Step 11: repeat Steps 6 through 10, until arranging all of the subpixels of the vectorimage in dif1.Figure 6
Assign a value ofimage to another position of vector dif1.Figure 7
Assign a value ofimage to an empty position of vector dif1.Figure 8
Locate an empty location indif1 to store the data.Diffusion I algorithm is shown in Algorithm1.Algorithm 1: Diffusion I.
Input:vector image,stardif1,x10,y10,z10,a1,b1,c1Output:vector dif1(1)
L=subpixels of image(2)
R=L/3(3)
i=1(4)
forj=1toRdo(5)
Chaosj=Solve Equation1with RungeKutta−4and keysx10,y10,z10,a1,b1,c1.(6)
end(7)
Loc=stardif1(8)
dif1Loc=imagei(9)
i=i+1(10)
forj=1toLdo(11)inc=roundchaosj+dif1Loc(12)
ifchaosj≥0then(13)
Loc=Loc+inc(14)seq=1(15)end(16)
elseifchaosj<0then(17)
Loc=Loc−inc(18)
seq=0(19)
end(20)ifdif1Locis NULLthen(21)dif1Loc=imagei(22)
end(23)elseifdif1Locis not NULLandseq=0then(24)
whiledif1Locis not NULL(25)
Loc=Loc−1(26)end(27)
dif1Loc=imagei(28)
end(29)
elseifdif1Locis not NULLandseq=1then(30)
whiledif1Locis not NULL(31)
Loc=Loc+1(32)end(33)
dif1Loc=imagei(34)end(35)i=i+1(36)
endConfusionStep 1: convert, to their value in pixel [0, 16777215], the elements ofdif1 and store them in a pix_image vector of R length:(9)pix_image=P1,P2,P3,…,PR.Step 2: resolveR times the system of equation (1) using encryption keys x20,y20,z20,a2,b2,c2, yielding as a result three orbits:(10)orbx=x21,x22,…,x2R,orby=y21,y22,…,y2R,orbz=z21,z22,…,z2R.Step 3: generate integer values between 0 and 16777215, dividing an element oforbx between the absolute value of the highest number of the vector, subsequently multiplying this by 16777215. The result is rounded off and the value of orbxi is substituted.(11)orbxi=roundorbxi/absHighestorbx∗16777215.Step 4: convert, to a 6-digit hexadecimal, each element ofpix_image, as shown in Figure 9.Confusion algorithm is shown in Algorithm2.Algorithm 2: Confusion.
Input:vector dif1,x20,y20,z20,a2,b2,c2,keyconf[0, 5], keyconf2 [0, 16777215].Output : vector conf(1)
pix_image=convert dif1to its values in pixels.(2)
R=length of pix_image.(3)
fori=1toRdo(4)
orbxi,orbyi,orbzi=Solve Equation1with RungeKutta−4and keysx20,y20,z20,a2,b2,c2.(5)
end(6)
fori=1toRdo(7)
orbxi=roundorbxi/highestorbx∗16777215(8)
end(9)
pix_image=convert to hexadecimalpix_image(10)
fori=1toRdo(11)
rotation=store6decimals of orbyi(12)pix_imagei=apply diffusionIpseudocode with keyconf,rotation and pix_imagei(13)
pix_imagei=convert to decimalpix_imagei(14)
end(15)
before=pix_image1(16)
cipher1=pix_image1XOR keyconf2(17)
fori=2toRdo(18)
cipher [i] = beforeXOR pix_image[i](19)
before=pix_imagei(20)
end(21)
fori=1toRdo(22)confi=orbxiXOR cipheri(23)
endFigure 9
Convert from decimal to hexadecimal.Step 5: store, inrotation, the first 6 decimals of an element of the vector orby, which will be utilized to indicate the number of times that each hexadecimal digit moves among the elements stored in the vector pix_image.Step 6: apply the algorithm of diffusion I to an element ofpix_image, taking into account the key keyconf and the positions indicated in rotation; later this is converted into a decimal, as can be observed in Figure 10.Step 7: repeat Steps 5 and 6 until applying the diffusion I algorithm to all elements ofpix_image.Step 8: store in the variablebefore an element of pix_image, later applying XOR between pix_imagei and keyconf2. Repeat this procedure to encrypt all elements of pix_image. However, from the second iteration, the value stored in before is used to apply XOR with the pix_image elements instead of keyconf2. The results will be stored in vector cipher. In this step, each pixel value is taken into account in order to apply confusion; thus, a modification in one of these will generate cascade changes in the cryptogram. This process is exhibited graphically in Figure 11.Step 9: apply XOR between vectorscipher and orbx, with the result stored in vector conf. The procedure is shown in Figure 12.Diffusion II. Take vectorconf and apply the procedure indicated in Diffusion I, but with keys x30,y30,z30,a3,b3,c3 and stardif2; in the end, the cryptogram is generated.Figure 10
Change the value of the pixel.Figure 11
Apply XOR to substitute the elements ofpix_image.Figure 12
Apply XOR betweencipher and orbx.


### 3.4.2. Algorithm for Decryption

Eliminate Diffusion IIStep 1: store the cryptogram’s subpixel vectorimage, which has a length of L=Rn+Gn+Bn.(12)image=R1,G1,B1,…,Rn,Gn,Bn.Step 2: create a vector calledconf of sizeL.Step 3: resolveR times the system of equation (1), with encryption keys x30,y30,z30,a3,b3,c3. The values generated of x3R,y3R,z3R are stored in a vector denominated chaos:(13)chaos=x31,y31,z31,…,x3R,y3R,z3R.Step 4: assign, to the variableLoc, the value of key startdif2.Step 5: take, from locationLoc in vector image, the value and place it in conf. This procedure is shown in Figure 13.(14)confi=imageLoc.Step 6: take the absolute value of an element of the vectorchaosj, later adding it to a value of confi, rounded off the result and assigning it to inc:(15)inc=roundabschaosj+confi.Step 7: verify ifchaosj≥0, then(16)Loc=Loc+incseq=1.Step 8: contrariwise, ifchaosj<0, then(17)Loc=Loc−incseq=0.Step 9: verify ifImageLoc has a value, assigning it to the next position in conf; contrariwise, proceed to Step 10 (see Figure 14).Step 10: in the case ofImageLoc being empty and seq=0, Loc will decrease; contrariwise, if seq=1, Loc increases. This procedure is carried out until finding a value and assigning it to conf (see Figure 15).(18)confi=imageLoc.Step 11: repeat Steps 6–10 until arranging allImage elements in conf.Eliminate diffusion II algorithm is shown in Algorithm3.Algorithm 3: Eliminate diffusion II.
Input:vector cryptogram,stardif2,x30,y30,z30,a3,b3,c3.Output:vector conf(1)
image=convert cryptogram to its values in subpixels.(2)
L=subpixels of image(3)
R=L/3(4)
i = 1(5)
forj=1toRdo(6)
Chaosj=Solve Equation1with RungeKutta−4and keysx30,y30,z30,a3,b3,c3.(7)
end(8)
Loc=stardif2(9)
confi=imageLoc(10)
i=i+1(11)
forj=1toLdo(11)
inc=roundchaosj+confi(12)ifchaosj≥0then(13)Loc=Loc+inc(14)seq=1(15)
end(16)
elseifchaosj<0then(17)Loc=Loc−inc(18)seq=0(19)
end(20)
ifimageLocis not NULLthen(21)confi=imageLoc(22)end(23)
elseifimageLocis NULLandseq=0then(24)whileimageLocis NULL(25)Loc=Loc−1(26)
end(27)
confi=imageLoc(28)
end(29)
elseifimageLocis NULLandseq=1then(30)
whileimageLocis NULL(31)Loc=Loc+1(32)end(33)
confi=imageLoc(34)end(35)
i=i+1(36)
endEliminate ConfusionStep 1: convert the elements of vectorconf from subpixels into pixels:(19)conf=P1,P2,P3,…,PR.Step 2: createorbx,orby,orbzStep2,confusion.Step 3: again, generate whole values between 0 and 16777215 (Step 3, confusion):(20)orbxi=roundorbxiabsHighestorbx∗16777215.Step 4: apply XOR betweenconf and orbx, with the result stored in cipher, as can be observed in Figure 16.Step 5: assign, to variablebefore and to vector pix_image, the result of applying XOR between the first element of cipher and keyconf2. Repeat this procedure to decrypt the entire vector cipher. But, from the second iteration, the value stored in before is utilized to apply XOR with the elements after cipher, instead of keyconf2, as can be observed in Figure 17.Step 6: regeneraterotation, taking the 6 first decimals of an element of vector orby.Step 7: implement the algorithm to eliminate diffusion II, taking an element ofpix_image, the key keyconf and the positions indicated in rotation; later, convert this into a decimal, as can be observed in Figure 18.Step 8: repeat Steps 6 and 7 until rearranging each element of vectorpix_image.Step 9: convertpix_image from a hexadecimal into a decimal.Eliminate confusion algorithm is shown in Algorithm4.Algorithm 4: Eliminate confusion.
Input:vector conf,x20,y20,z20,a2,b2,c2,keyconf[0, 5], keyconf2 [0, 16777215].Output:vector pix_image(1)
conf=convert conf to its values in pixels.(2)
R=pixels of conf.(3)
fori=1toRdo(4)
orbxi,orbyi,orbzi=Solve Equation1with RungeKutta−4and keysx20,y20,z20,a2,b2,c2.(5)
end(6)
fori=1toRdo(7)
orbxi=roundorbxi/highestorbx∗16777215(8)
end(9)
fori=1toRdo(10)
cipheri=orbxiXOR confi(11)
end(12)
before=cipher1XOR keyconf2(13)
pix_image1=before(14)
fori=2toRdo(15)
pix_image [i] = beforeXOR cipheri(16)before=pix_imagei(17)
end(18)
pix_image=convert to hexadecimalpix_image(19)
fori=1toRdo(20)rotation=store6decimals of orbyi(21)
pix_imagei=apply eliminate diffusion II with keyconf,rotation  and pix_imagei(22)pix_imagei=convert to decimalpix_imagei(23)
endEliminate Diffusion I. Take vectorpix_image and apply the procedure indicated in Eliminate Diffusion II, but with keys x10,y10,z10,a1,b1,c1,and stardif1; finally, the original image is recovered.Figure 13
Place the value ofimage in its original position in vector.Figure 14
Assign the value of the vectorimage in position Loc in vector conf.Figure 15
Localize the following site with a datum in the vectorimage.Figure 16
ApplyXOR between confand orbx.Figure 17
Restore the vectorpix_image, reverting XOR to cascade.Figure 18
Restore the value of the pixel.


## 3.4.1. Algorithm to Encrypt

The encryption algorithm can work with any chaotic mathematical model one wishes to employ, as long as the required number of orbits is generated. The Rössler oscillator is implemented because it generates three complex chaotic sequences, is highly sensitive to initial conditions and system parameters, and uses six keys each time it is resolved, generating a very wide key space.Keys(i)
Diffusionx10,y10,z10,a1,b1,c1: values corresponding to the initial conditions and parameters used to apply Diffusion I, when the chaotic system of the Rössler oscillator is resolved (equation (1)). x30,y30,z30,a3,b3,c3: keys utilized to apply Diffusion II.startdif1,stardif2: the keys necessary in the two diffusion processes, which are utilized as initial position and that can be taken between 1 and L; where L=width_image ∗ height_image ∗3.(ii)
Confusionx20,y20,z20,a2,b2,c2: these initial conditions and parameters are also utilized to resolve the Rössler oscillator (equation (1)).keyconf: initial position between 0 and 5.keyconf2: value between 0 and 16777215, which is employed to select a position.Apply Diffusion IEach face is broken down into the pixels comprising it, and later into their 3 subpixels (red, green, blue (RGB)), which have a value between 0 and 255.Step 1: store in a vector of lengthL, called image, the subpixels of the face:(2)image=R1,G1,B1,…,Rn,Gn,Bn.Step 2: create a vector calleddif1 of size L.Step 3: resolveR times the system of equation (1), implementing the encryption keys of x10,y10,z10,a1,b1,c1; where R = width_image ∗ height_image. The values generated of x1R,y1R,z1R are stored in a vector called chaos of length L=3∗R:(3)chaos=x11,y11,z11,…,x1R,y1R,z1R.Step 4: assign, to the variableLoc, the value of the key startdif1.Step 5: take a value ofimage and assign it to location Loc of vector dif1, as can be observed in Figure 6:(4)dif1Loc=imagei.Step 6: take the absolute value of an element of the vectorchaosj, later adding to it dif1Loc; finally, the result is rounded off and is assigned to the variable inc:(5)inc=roundabschaosj+dif1Loc.Step 7: verify ifchaosj≥0, then(6)Loc=Loc+incseq=1.Step 8: else, ifchaosj<0, then(7)Loc=Loc−incseq=0.Step 9: verify ifdif1Loc is empty, assigning to it an element of image; else, go to Step 10 (see Figure 7).Step 10: verify ifdif1Loc is not empty and seq=0, Loc is decreasing, until finding a formerly empty location; contrariwise, if seq=1, Loc increases. On localizing an empty position, assign to it the element of image. This procedure is presented in Figure 8.(8)dif1Loc=imagei.Step 11: repeat Steps 6 through 10, until arranging all of the subpixels of the vectorimage in dif1.Figure 6
Assign a value ofimage to another position of vector dif1.Figure 7
Assign a value ofimage to an empty position of vector dif1.Figure 8
Locate an empty location indif1 to store the data.Diffusion I algorithm is shown in Algorithm1.Algorithm 1: Diffusion I.
Input:vector image,stardif1,x10,y10,z10,a1,b1,c1Output:vector dif1(1)
L=subpixels of image(2)
R=L/3(3)
i=1(4)
forj=1toRdo(5)
Chaosj=Solve Equation1with RungeKutta−4and keysx10,y10,z10,a1,b1,c1.(6)
end(7)
Loc=stardif1(8)
dif1Loc=imagei(9)
i=i+1(10)
forj=1toLdo(11)inc=roundchaosj+dif1Loc(12)
ifchaosj≥0then(13)
Loc=Loc+inc(14)seq=1(15)end(16)
elseifchaosj<0then(17)
Loc=Loc−inc(18)
seq=0(19)
end(20)ifdif1Locis NULLthen(21)dif1Loc=imagei(22)
end(23)elseifdif1Locis not NULLandseq=0then(24)
whiledif1Locis not NULL(25)
Loc=Loc−1(26)end(27)
dif1Loc=imagei(28)
end(29)
elseifdif1Locis not NULLandseq=1then(30)
whiledif1Locis not NULL(31)
Loc=Loc+1(32)end(33)
dif1Loc=imagei(34)end(35)i=i+1(36)
endConfusionStep 1: convert, to their value in pixel [0, 16777215], the elements ofdif1 and store them in a pix_image vector of R length:(9)pix_image=P1,P2,P3,…,PR.Step 2: resolveR times the system of equation (1) using encryption keys x20,y20,z20,a2,b2,c2, yielding as a result three orbits:(10)orbx=x21,x22,…,x2R,orby=y21,y22,…,y2R,orbz=z21,z22,…,z2R.Step 3: generate integer values between 0 and 16777215, dividing an element oforbx between the absolute value of the highest number of the vector, subsequently multiplying this by 16777215. The result is rounded off and the value of orbxi is substituted.(11)orbxi=roundorbxi/absHighestorbx∗16777215.Step 4: convert, to a 6-digit hexadecimal, each element ofpix_image, as shown in Figure 9.Confusion algorithm is shown in Algorithm2.Algorithm 2: Confusion.
Input:vector dif1,x20,y20,z20,a2,b2,c2,keyconf[0, 5], keyconf2 [0, 16777215].Output : vector conf(1)
pix_image=convert dif1to its values in pixels.(2)
R=length of pix_image.(3)
fori=1toRdo(4)
orbxi,orbyi,orbzi=Solve Equation1with RungeKutta−4and keysx20,y20,z20,a2,b2,c2.(5)
end(6)
fori=1toRdo(7)
orbxi=roundorbxi/highestorbx∗16777215(8)
end(9)
pix_image=convert to hexadecimalpix_image(10)
fori=1toRdo(11)
rotation=store6decimals of orbyi(12)pix_imagei=apply diffusionIpseudocode with keyconf,rotation and pix_imagei(13)
pix_imagei=convert to decimalpix_imagei(14)
end(15)
before=pix_image1(16)
cipher1=pix_image1XOR keyconf2(17)
fori=2toRdo(18)
cipher [i] = beforeXOR pix_image[i](19)
before=pix_imagei(20)
end(21)
fori=1toRdo(22)confi=orbxiXOR cipheri(23)
endFigure 9
Convert from decimal to hexadecimal.Step 5: store, inrotation, the first 6 decimals of an element of the vector orby, which will be utilized to indicate the number of times that each hexadecimal digit moves among the elements stored in the vector pix_image.Step 6: apply the algorithm of diffusion I to an element ofpix_image, taking into account the key keyconf and the positions indicated in rotation; later this is converted into a decimal, as can be observed in Figure 10.Step 7: repeat Steps 5 and 6 until applying the diffusion I algorithm to all elements ofpix_image.Step 8: store in the variablebefore an element of pix_image, later applying XOR between pix_imagei and keyconf2. Repeat this procedure to encrypt all elements of pix_image. However, from the second iteration, the value stored in before is used to apply XOR with the pix_image elements instead of keyconf2. The results will be stored in vector cipher. In this step, each pixel value is taken into account in order to apply confusion; thus, a modification in one of these will generate cascade changes in the cryptogram. This process is exhibited graphically in Figure 11.Step 9: apply XOR between vectorscipher and orbx, with the result stored in vector conf. The procedure is shown in Figure 12.Diffusion II. Take vectorconf and apply the procedure indicated in Diffusion I, but with keys x30,y30,z30,a3,b3,c3 and stardif2; in the end, the cryptogram is generated.Figure 10
Change the value of the pixel.Figure 11
Apply XOR to substitute the elements ofpix_image.Figure 12
Apply XOR betweencipher and orbx.


## 3.4.2. Algorithm for Decryption

Eliminate Diffusion IIStep 1: store the cryptogram’s subpixel vectorimage, which has a length of L=Rn+Gn+Bn.(12)image=R1,G1,B1,…,Rn,Gn,Bn.Step 2: create a vector calledconf of sizeL.Step 3: resolveR times the system of equation (1), with encryption keys x30,y30,z30,a3,b3,c3. The values generated of x3R,y3R,z3R are stored in a vector denominated chaos:(13)chaos=x31,y31,z31,…,x3R,y3R,z3R.Step 4: assign, to the variableLoc, the value of key startdif2.Step 5: take, from locationLoc in vector image, the value and place it in conf. This procedure is shown in Figure 13.(14)confi=imageLoc.Step 6: take the absolute value of an element of the vectorchaosj, later adding it to a value of confi, rounded off the result and assigning it to inc:(15)inc=roundabschaosj+confi.Step 7: verify ifchaosj≥0, then(16)Loc=Loc+incseq=1.Step 8: contrariwise, ifchaosj<0, then(17)Loc=Loc−incseq=0.Step 9: verify ifImageLoc has a value, assigning it to the next position in conf; contrariwise, proceed to Step 10 (see Figure 14).Step 10: in the case ofImageLoc being empty and seq=0, Loc will decrease; contrariwise, if seq=1, Loc increases. This procedure is carried out until finding a value and assigning it to conf (see Figure 15).(18)confi=imageLoc.Step 11: repeat Steps 6–10 until arranging allImage elements in conf.Eliminate diffusion II algorithm is shown in Algorithm3.Algorithm 3: Eliminate diffusion II.
Input:vector cryptogram,stardif2,x30,y30,z30,a3,b3,c3.Output:vector conf(1)
image=convert cryptogram to its values in subpixels.(2)
L=subpixels of image(3)
R=L/3(4)
i = 1(5)
forj=1toRdo(6)
Chaosj=Solve Equation1with RungeKutta−4and keysx30,y30,z30,a3,b3,c3.(7)
end(8)
Loc=stardif2(9)
confi=imageLoc(10)
i=i+1(11)
forj=1toLdo(11)
inc=roundchaosj+confi(12)ifchaosj≥0then(13)Loc=Loc+inc(14)seq=1(15)
end(16)
elseifchaosj<0then(17)Loc=Loc−inc(18)seq=0(19)
end(20)
ifimageLocis not NULLthen(21)confi=imageLoc(22)end(23)
elseifimageLocis NULLandseq=0then(24)whileimageLocis NULL(25)Loc=Loc−1(26)
end(27)
confi=imageLoc(28)
end(29)
elseifimageLocis NULLandseq=1then(30)
whileimageLocis NULL(31)Loc=Loc+1(32)end(33)
confi=imageLoc(34)end(35)
i=i+1(36)
endEliminate ConfusionStep 1: convert the elements of vectorconf from subpixels into pixels:(19)conf=P1,P2,P3,…,PR.Step 2: createorbx,orby,orbzStep2,confusion.Step 3: again, generate whole values between 0 and 16777215 (Step 3, confusion):(20)orbxi=roundorbxiabsHighestorbx∗16777215.Step 4: apply XOR betweenconf and orbx, with the result stored in cipher, as can be observed in Figure 16.Step 5: assign, to variablebefore and to vector pix_image, the result of applying XOR between the first element of cipher and keyconf2. Repeat this procedure to decrypt the entire vector cipher. But, from the second iteration, the value stored in before is utilized to apply XOR with the elements after cipher, instead of keyconf2, as can be observed in Figure 17.Step 6: regeneraterotation, taking the 6 first decimals of an element of vector orby.Step 7: implement the algorithm to eliminate diffusion II, taking an element ofpix_image, the key keyconf and the positions indicated in rotation; later, convert this into a decimal, as can be observed in Figure 18.Step 8: repeat Steps 6 and 7 until rearranging each element of vectorpix_image.Step 9: convertpix_image from a hexadecimal into a decimal.Eliminate confusion algorithm is shown in Algorithm4.Algorithm 4: Eliminate confusion.
Input:vector conf,x20,y20,z20,a2,b2,c2,keyconf[0, 5], keyconf2 [0, 16777215].Output:vector pix_image(1)
conf=convert conf to its values in pixels.(2)
R=pixels of conf.(3)
fori=1toRdo(4)
orbxi,orbyi,orbzi=Solve Equation1with RungeKutta−4and keysx20,y20,z20,a2,b2,c2.(5)
end(6)
fori=1toRdo(7)
orbxi=roundorbxi/highestorbx∗16777215(8)
end(9)
fori=1toRdo(10)
cipheri=orbxiXOR confi(11)
end(12)
before=cipher1XOR keyconf2(13)
pix_image1=before(14)
fori=2toRdo(15)
pix_image [i] = beforeXOR cipheri(16)before=pix_imagei(17)
end(18)
pix_image=convert to hexadecimalpix_image(19)
fori=1toRdo(20)rotation=store6decimals of orbyi(21)
pix_imagei=apply eliminate diffusion II with keyconf,rotation  and pix_imagei(22)pix_imagei=convert to decimalpix_imagei(23)
endEliminate Diffusion I. Take vectorpix_image and apply the procedure indicated in Eliminate Diffusion II, but with keys x10,y10,z10,a1,b1,c1,and stardif1; finally, the original image is recovered.Figure 13
Place the value ofimage in its original position in vector.Figure 14
Assign the value of the vectorimage in position Loc in vector conf.Figure 15
Localize the following site with a datum in the vectorimage.Figure 16
ApplyXOR between confand orbx.Figure 17
Restore the vectorpix_image, reverting XOR to cascade.Figure 18
Restore the value of the pixel.


## 4. Results

The proposed communication system works with images in the .png format and implements the OpenCV Library for face detection and identification. We use this library to determine the characteristics that photographs must possess to encrypt faces more effectively; 171 photographs of 1,280 x 960, 4,032 x 3,024, and 2,704 x 2,652, with controlled, semicontrolled, and uncontrolled environments, were used. According to the tests, it was discovered that detection affects the lighting, the angle of the face, and the facial expressions; also, in the OpenCV Library in semicontrolled environments where one wants to identify more than one person, some faces were correctly identified and encrypted, but others were not. Based on these results, it was determined that it is best to use the photographs in controlled environments for the system to function properly. In semicontrolled and uncontrolled environments, it is best to use the system manually.Table1 presents the results generated with the tests. Positive indicates that detection, recognition, and encryption worked correctly. In the intermediate, some faces were not recognized or were confused with that of another person, and in the negatives, it did not recognize persons.Table 1
Results of the tests with 171 images.
TypeTotal photosPositiveIntermediateNegativeControlled4444——Semicontrolled10867338Uncontrolled19——19Total1711113327To verify the robustness of the encryption system, the statistical analysis is presented in this section, as well as different attacks of the algorithm proposed, and this is compared with the results of other investigations. Figure19(a) shows the Lena image of 256 x 256 that is used for all tests, Figure 19(b) shows the cryptogram generated when applying diffusion technique I, Figure 19(c) represents the cryptogram when implementing only the confusion technique, Figure 19(d) shows the cryptogram that was generated using diffusion I and confusion, and Figure 19(e) presents the cryptogram with the diffusion I-confusion-diffusion II techniques. The decryption process is presented in Figure 19(f), which presents the cryptogram obtained when eliminating diffusion II, Figure 19(g) shows the cryptogram when confusion and diffusion II are eliminated, that is, only with the diffusion I technique, and Figure 19(h) shows the decrypted image. It can be clearly observed that, individually, both the diffusion technique (Figure 19(b)) and the confusion technique (Figure 19(c)) render the image unrecognizable.Figure 19
Encryption and decryption process: (a) original image, (b) cryptogram with diffusion I, (c) cryptogram with confusion, (d) cryptogram with diffusion I and confusion, (e) full cryptogram with diffusion I, confusion, and diffusion II, (f) cryptogram recovered by removing diffusion II, (g) cryptogram recovered by removing diffusion II and confusion, and (h) decrypted image.
(a)(b)(c)(d)(e)(f)(g)(h)


### 4.1. Statistical Analysis

#### 4.1.1. Histograms

In Figures20(a), 20(c), and 20(e), the histograms are presented of the RGB channels corresponding to Figure 19(a) and to the images of Figures 20(b), 20(d), and 20(f)), those of the cryptogram of Figure 19(e). As can be observed, there are no similarities in the distributions of the color frequencies between the original image and the cryptogram. That is, on observing the histograms corresponding to the cryptogram, it can be clearly seen that there is greater homogeneity in contrast with the originals; therefore, it is difficult for an attacker to find a relation between the original image and the cryptogram.Figure 20
Analysis of histograms: (a, c, e) original image of Lena red, green, and blue, respectively; (b, d, f) the histograms of the red, green, and blue channel cryptogram.
(a)(b)(c)(d)(e)(f)


#### 4.1.2. Correlation

These permit the detection of the linear relation between two variables or images; this analysis yields anR correlation coefficient, which is found within the range of [−1 to 1]: the more it nears 1 and −1, the more both images are similar or alike if they yield these exact values. On the other hand, the nearer they are to 0, the greater the number of differences, or they are completely different if R=0.Figure21 presents the correlation diagram of the original image with respect to the cryptogram, and it can be observed that coefficient R=0.00000267625 is very close to 0; thus, it is more difficult for an attacker to attempt to find a relation between both of these.Figure 21
Diagram of the correlation between the original image vs. the cryptogram.In Figure22, the correlation is able to be observed of the original image vs. the decrypted one, which yields the result of R=1. Thus, the encrypted system guarantees integrity on recovering 100% of the information.Figure 22
Diagram of the correlation of the original image vs. the decrypted.In Table2, the results are shown of the correlation analysis. In the first column, the coefficient correlation is presented as generated on comparing the original image vs. the cryptogram; later, the original image was compared vs. the decrypted, with the results presented in column 2. As can be observed, our cryptosystem presents excellent results in comparison with those of other state-of-the-art cryptosystems.Table 2
Comparison of correlation coefficients.
CryptogramDecryptReference0.000002676251Proposed0.0028511[25]0.000686—[26]The correlation coefficient was calculated of 1,000 pairs of pixels taken at random, that is, the original image as well as the cryptogram horizontally, vertically, and diagonally, according to components R, G, and B. Figures23(a)–23(i) present the correlation diagrams generated from the original image, while those of Figures 24(a)–24(i) depict the distribution of the cryptograms.Figure 23
Correlation of pairs of the horizontal, vertical, and diagonal pixels of the original image according to the RGB channels.
(a)(b)(c)(d)(e)(f)(g)(h)(i)Figure 24
Correlation of horizontal, vertical, and diagonal pixels of the cryptogram according to the RGB channels.
(a)(b)(c)(d)(e)(f)(g)(h)(i)Table3 displays the correlation coefficients of Figures 23(a)–23(i) and of Figures 24(a)–24(i), which are compared with those of other investigations.Table 3
Coefficient of the horizontal, vertical, and diagonal correlation of pairs of adjacent pixels.
DistributionPlane imageEncrypted imageReferenceRGBRGBHorizontal0.9567——-0.0026——[27]Vertical0.9239——-0.0038——Diagonal0.8888——0.0017——Horizontal0.98430.97930.87840.0181−0.00670.0154[21]Vertical0.99280.98780.9204−0.00990.01260.0063Diagonal0.98100.97420.87170.00850.0127−0.0155Horizontal0.9335610.9056380.859151−0.00020268−0.00153669−0.00343206[28]Vertical0.96380.9464690.905638−0.000144000.00405293−0.00555131Diagonal0.9352890.9077030.860089−0.00309766−0.000400902−0.00026181Horizontal0.933380.90490.8597−0.0137−0.00490.0038[29]Vertical0.96410.94670.90610.0038−0.00080.0017Diagonal0.90740.88020.83830.0036−0.00120.0008Horizontal0.911170.899720.82821−0.0006840340.0000532805−0.000996056ProposedVertical0.942350.930020.870040.000861182−0.0009328790.00169Diagonal0.863730.845640.729950.00168−0.001−0.000996454Table4 presents a comparison of the horizontal, vertical, and diagonal distribution of channels R, G, and B, but now taking into account 5,000 pairs of adjacent pixels.Table 4
Coefficient of horizontal, vertical, and diagonal correlation of 5,000 pairs of adjacent pixels.
DistributionPlane imageEncrypted imageReferenceRGBRGBHorizontal0.9326670295864560.9222814932333490.8938252193918210.003535161409385−0.0097068716354860.018571551282381[30]Vertical0.9624087631313620.9546935078297540.934300708191352−0.0040763247259520.0053120320280560.010691355134514Diagonal0.9079660093985850.8804087760213110.863453990135567−0.041028497842243−0.008522993738987−0.017458909511577Horizontal0.97770.96040.91010.0135−0.0835−0.0170[31]Horizontal0.916690.860710.828290.00011123−0.000197324−0.000194282ProposedVertical0.9350.918650.87415−0.0001267170.000388285−0.000196329Diagonal0.874050.843510.78519−0.0000893574−0.000165072−0.000191976In the results of Tables3 and 4, it can be clearly observed that our system generates a correlation in the cryptograms that is much closer to 0, nearly null. Therefore, the proposed encryption technique renders the loss of the relation among adjacent pixels in the three directions.


#### 4.1.3. Entropy

Entropy allows verification of the level of randomness or of how unpredictable the pixel values are in an image, which is the determination of the level of disorder of a cryptogram: the more the latter nears 8 or is equal to it, the better the processes of diffusion and confusion of the cryptogram and is more robust to an entropy attack, due to the degree of randomness of the cryptograms. Thus, this is unpredictable. Table5 depicts the entropy of the proposed system and compares it with other systems.Table 5
Entropy of different systems of encryption.
EntropyReference7.999[32]7.9988[33]7.997[31]7.997[34]7.997133[28]7.99654[29]7.9998[19]7.9988Proposed


#### 4.1.4. NPCR (Number of Pixel Change Rate)

The NPCR permits the determination of the strength of the encryption with respect to a differential attack; that is, it determines the percentage of changes in the location of the pixels of two images. NPCR should yield a value near 100%, indicating that both images are very different.


#### 4.1.5. UACI (Unified Average Changed Intensity)

The average is calculated of the differences in the intensity of the pixels of the two images. This should yield a result greater than 33%.NPCR and UACI were calculated with two cryptograms generated with nearly all of the same keys, with the exception of one carried out with a small change in the least significant decimal digit. NPCR results were obtained of above 99% and those of UACI were above 33%. Therefore, the proposed system takes as input a plane image and with a small change, generating a very different cryptogram. Table6 presents the results of this analysis.Table 6
NPCR and UACI of cryptograms encrypted with a small change in one of their keys.
AnalysisRGBReferenceNPCR99.655299.627799.588[27]UACI33.484633.413233.3441NPCR99.597199.600299.6368ProposedUACI33.389533.292533.5537In Table7, the result is presented of the analysis of the NPCR and UACI of the two cryptograms that were generated from the two images that were only differentiated because in one of these, the least significant bit of a red subpixel was changed; it also yielded NPCR> 99% and UACI> 33 as a result. Therefore, the proposed system is very sensitive to the plane image and would provide robustness when encountering a differential attack.Table 7
NPCR and UACI of cryptograms encrypted with a change in one of the subpixels.
AnalysisRGBReferenceNPCR99.6399.6099.61[31]UACI33.3133.3433.43NPCR99.565999.565899.5959[21]UACI33.282933.345933.3270NPCR99.642999.614099.6277[20]UACI33.393533.563733.4814NPCR99.612499.614099.6201[28]UACI33.423533.483833.5983NPCR99.598699.617099.6231ProposedUACI33.407433.564533.5042


#### 4.1.6. Avalanche Effect

This analysis reflects the sensitivity of the encryption algorithms to a small change in the parameters (in the key or in the plane text) of the entry information, which should cause a great change in the cryptogram [35].This test was utilized to verify the differences between the two Lena images, in which, in one of these the least significant bit was modified in channel R in one of the initial pixels, and later compared with another without any change. Figure25(a) depicts the remainder between the two pixels and difference was able to be appreciated clearly. Figure 25(b) presents the remainder of the two pixels of the 2 cryptograms generated on encrypting the 2 Lena images, and it can be clearly seen that these are different. The proposed algorithm passes this test due to that the diffusion technique is applied on two occasions and, in addition, the pixels were taken into account on coding during confusion.Figure 25
Avalanche effect: (a) difference at the initiation of a Lena image; (b) differences in the cryptograms.
(a)(b)Figures26(a) and 26(b) present the tests carried out of the avalanche effect, but with the least significant bit of the R channel altered at the end of one of the Lena images.Figure 26
Avalanche effect: (a) difference of channel R at the end of one of the Lena images; (b) difference of the cryptograms.
(a)(b)


#### 4.1.7. Sensitivity of the Key

To verify whether the image can be recovered with different keys, Figure19(a) was encrypted with the keys of Table 8, generating the cryptogram of Figure 27(a), which was recovered correctly utilizing the same keys with which it was encrypted (Figure 27(b)). Recovery was also attempted by the alteration of x30 of 0.75749573951 to 0.75749573952, yielding as a result Figure 27(c). With the latter, it was proven that, on performing a small change in one of the keys, the image was unable to be recovered correctly.Table 8
Keys employed for encryption.
Diffusion IConfusionDiffusion IIx10=3.75846375846x20=2.58395739578x30=0.75749573951y10=1.37483648365y20=1.27490458294y30=−4.4839573944z10=7.29347658364z20=7.57395729493z30=−12.391038593a1=0.25783958392a2=0.15639204821a3=0.22491840583b1=5.74950385024b2=18.1749374935b3=15.1947394573c1=0.57583759382c2=0.16739275921c3=0.10385738593startdif1=15keyconf=3startdif2=89483—keyconf2=138495—Figure 27
Test of the sensitivity of the key.


#### 4.1.8. Speed Tests

Algorithm speed was tested in an Omen 17 An101la laptop, with an Intel Core i7-8750 H 2.20 GHz processor, a Wester Digital Black 512 GB SSD hard drive, 16 GB RAM DDR4-2666 MHz, and the encryption algorithm was performed with Java language programming. Table9 presents a comparison of the encryption speed of the proposed system with other investigations.Table 9
Encryption time (seconds).
Image (pixels)Proposed[31][19][26][36]256 x 2560.1344380.06570.21512 x 5120.412850.24320.0070.2901.19


#### 4.1.9. Key Space

The key space defines the number of different keys that can be used by a cryptosystem. The proposed algorithm uses six in diffusion technique Ix10,y10,z10,a1,b1,c1, another six when diffusion II is implemented x30,y30,z30,a3,b3,c3, and also, when implementing confusion, yet other six keys are used x20,y20,z20,a2,b2,c2. The precision of the floating-point number is 10−15; therefore, the key space is 10270≈2896. Additionally, the keys keyconf, keyconf2, startdif1,and stardif2 are implemented with a variable key space. Table 10 depicts a comparison of the space key of the proposed system with other investigations.Table 10
Secret key space.
Proposed[31][37][36][26][19][34][28]28964 variable keys 1027021282192220022982256101121058For the cryptosystem to be safe, there must be a key space greater than 2100 [38]; therefore, the proposed system will support a brute force attack.


#### 4.1.10. Encryption Quality Analysis

To verify the quality of the encryption, we calculated the maximum deviation: to evaluate the deviation between the intensity of pixels of the original image and the cryptogram. If the value is high, the quality of the encryption is good. Irregular deviation allows to statistically evaluate the quality of the intensity of the pixels in the cryptogram. If it is high, the pixels are uniformly distributed. Deviation from ideality: this detects the probability of distribution of the pixels in the cryptogram. The closer to zero it is, the better the quality of the cryptogram [39]. (Table 11)Table 11
Encryption quality analysis.
Maximum deviationIrregular deviationDeviation from idealityReferenceRGBRGBRGB83,91281,294.587,629.532,10233,45338,1590.048520.047390.05227[28]5.0069 × 10436,47365,82645,90625,14027500.77340.54920.9882[29]36,43759,52670,23237,46860,53071,2380.0034637450.003829950.00369262Proposed


## 4.1. Statistical Analysis

### 4.1.1. Histograms

In Figures20(a), 20(c), and 20(e), the histograms are presented of the RGB channels corresponding to Figure 19(a) and to the images of Figures 20(b), 20(d), and 20(f)), those of the cryptogram of Figure 19(e). As can be observed, there are no similarities in the distributions of the color frequencies between the original image and the cryptogram. That is, on observing the histograms corresponding to the cryptogram, it can be clearly seen that there is greater homogeneity in contrast with the originals; therefore, it is difficult for an attacker to find a relation between the original image and the cryptogram.Figure 20
Analysis of histograms: (a, c, e) original image of Lena red, green, and blue, respectively; (b, d, f) the histograms of the red, green, and blue channel cryptogram.
(a)(b)(c)(d)(e)(f)


### 4.1.2. Correlation

These permit the detection of the linear relation between two variables or images; this analysis yields anR correlation coefficient, which is found within the range of [−1 to 1]: the more it nears 1 and −1, the more both images are similar or alike if they yield these exact values. On the other hand, the nearer they are to 0, the greater the number of differences, or they are completely different if R=0.Figure21 presents the correlation diagram of the original image with respect to the cryptogram, and it can be observed that coefficient R=0.00000267625 is very close to 0; thus, it is more difficult for an attacker to attempt to find a relation between both of these.Figure 21
Diagram of the correlation between the original image vs. the cryptogram.In Figure22, the correlation is able to be observed of the original image vs. the decrypted one, which yields the result of R=1. Thus, the encrypted system guarantees integrity on recovering 100% of the information.Figure 22
Diagram of the correlation of the original image vs. the decrypted.In Table2, the results are shown of the correlation analysis. In the first column, the coefficient correlation is presented as generated on comparing the original image vs. the cryptogram; later, the original image was compared vs. the decrypted, with the results presented in column 2. As can be observed, our cryptosystem presents excellent results in comparison with those of other state-of-the-art cryptosystems.Table 2
Comparison of correlation coefficients.
CryptogramDecryptReference0.000002676251Proposed0.0028511[25]0.000686—[26]The correlation coefficient was calculated of 1,000 pairs of pixels taken at random, that is, the original image as well as the cryptogram horizontally, vertically, and diagonally, according to components R, G, and B. Figures23(a)–23(i) present the correlation diagrams generated from the original image, while those of Figures 24(a)–24(i) depict the distribution of the cryptograms.Figure 23
Correlation of pairs of the horizontal, vertical, and diagonal pixels of the original image according to the RGB channels.
(a)(b)(c)(d)(e)(f)(g)(h)(i)Figure 24
Correlation of horizontal, vertical, and diagonal pixels of the cryptogram according to the RGB channels.
(a)(b)(c)(d)(e)(f)(g)(h)(i)Table3 displays the correlation coefficients of Figures 23(a)–23(i) and of Figures 24(a)–24(i), which are compared with those of other investigations.Table 3
Coefficient of the horizontal, vertical, and diagonal correlation of pairs of adjacent pixels.
DistributionPlane imageEncrypted imageReferenceRGBRGBHorizontal0.9567——-0.0026——[27]Vertical0.9239——-0.0038——Diagonal0.8888——0.0017——Horizontal0.98430.97930.87840.0181−0.00670.0154[21]Vertical0.99280.98780.9204−0.00990.01260.0063Diagonal0.98100.97420.87170.00850.0127−0.0155Horizontal0.9335610.9056380.859151−0.00020268−0.00153669−0.00343206[28]Vertical0.96380.9464690.905638−0.000144000.00405293−0.00555131Diagonal0.9352890.9077030.860089−0.00309766−0.000400902−0.00026181Horizontal0.933380.90490.8597−0.0137−0.00490.0038[29]Vertical0.96410.94670.90610.0038−0.00080.0017Diagonal0.90740.88020.83830.0036−0.00120.0008Horizontal0.911170.899720.82821−0.0006840340.0000532805−0.000996056ProposedVertical0.942350.930020.870040.000861182−0.0009328790.00169Diagonal0.863730.845640.729950.00168−0.001−0.000996454Table4 presents a comparison of the horizontal, vertical, and diagonal distribution of channels R, G, and B, but now taking into account 5,000 pairs of adjacent pixels.Table 4
Coefficient of horizontal, vertical, and diagonal correlation of 5,000 pairs of adjacent pixels.
DistributionPlane imageEncrypted imageReferenceRGBRGBHorizontal0.9326670295864560.9222814932333490.8938252193918210.003535161409385−0.0097068716354860.018571551282381[30]Vertical0.9624087631313620.9546935078297540.934300708191352−0.0040763247259520.0053120320280560.010691355134514Diagonal0.9079660093985850.8804087760213110.863453990135567−0.041028497842243−0.008522993738987−0.017458909511577Horizontal0.97770.96040.91010.0135−0.0835−0.0170[31]Horizontal0.916690.860710.828290.00011123−0.000197324−0.000194282ProposedVertical0.9350.918650.87415−0.0001267170.000388285−0.000196329Diagonal0.874050.843510.78519−0.0000893574−0.000165072−0.000191976In the results of Tables3 and 4, it can be clearly observed that our system generates a correlation in the cryptograms that is much closer to 0, nearly null. Therefore, the proposed encryption technique renders the loss of the relation among adjacent pixels in the three directions.


### 4.1.3. Entropy

Entropy allows verification of the level of randomness or of how unpredictable the pixel values are in an image, which is the determination of the level of disorder of a cryptogram: the more the latter nears 8 or is equal to it, the better the processes of diffusion and confusion of the cryptogram and is more robust to an entropy attack, due to the degree of randomness of the cryptograms. Thus, this is unpredictable. Table5 depicts the entropy of the proposed system and compares it with other systems.Table 5
Entropy of different systems of encryption.
EntropyReference7.999[32]7.9988[33]7.997[31]7.997[34]7.997133[28]7.99654[29]7.9998[19]7.9988Proposed


### 4.1.4. NPCR (Number of Pixel Change Rate)

The NPCR permits the determination of the strength of the encryption with respect to a differential attack; that is, it determines the percentage of changes in the location of the pixels of two images. NPCR should yield a value near 100%, indicating that both images are very different.


### 4.1.5. UACI (Unified Average Changed Intensity)

The average is calculated of the differences in the intensity of the pixels of the two images. This should yield a result greater than 33%.NPCR and UACI were calculated with two cryptograms generated with nearly all of the same keys, with the exception of one carried out with a small change in the least significant decimal digit. NPCR results were obtained of above 99% and those of UACI were above 33%. Therefore, the proposed system takes as input a plane image and with a small change, generating a very different cryptogram. Table6 presents the results of this analysis.Table 6
NPCR and UACI of cryptograms encrypted with a small change in one of their keys.
AnalysisRGBReferenceNPCR99.655299.627799.588[27]UACI33.484633.413233.3441NPCR99.597199.600299.6368ProposedUACI33.389533.292533.5537In Table7, the result is presented of the analysis of the NPCR and UACI of the two cryptograms that were generated from the two images that were only differentiated because in one of these, the least significant bit of a red subpixel was changed; it also yielded NPCR> 99% and UACI> 33 as a result. Therefore, the proposed system is very sensitive to the plane image and would provide robustness when encountering a differential attack.Table 7
NPCR and UACI of cryptograms encrypted with a change in one of the subpixels.
AnalysisRGBReferenceNPCR99.6399.6099.61[31]UACI33.3133.3433.43NPCR99.565999.565899.5959[21]UACI33.282933.345933.3270NPCR99.642999.614099.6277[20]UACI33.393533.563733.4814NPCR99.612499.614099.6201[28]UACI33.423533.483833.5983NPCR99.598699.617099.6231ProposedUACI33.407433.564533.5042


### 4.1.6. Avalanche Effect

This analysis reflects the sensitivity of the encryption algorithms to a small change in the parameters (in the key or in the plane text) of the entry information, which should cause a great change in the cryptogram [35].This test was utilized to verify the differences between the two Lena images, in which, in one of these the least significant bit was modified in channel R in one of the initial pixels, and later compared with another without any change. Figure25(a) depicts the remainder between the two pixels and difference was able to be appreciated clearly. Figure 25(b) presents the remainder of the two pixels of the 2 cryptograms generated on encrypting the 2 Lena images, and it can be clearly seen that these are different. The proposed algorithm passes this test due to that the diffusion technique is applied on two occasions and, in addition, the pixels were taken into account on coding during confusion.Figure 25
Avalanche effect: (a) difference at the initiation of a Lena image; (b) differences in the cryptograms.
(a)(b)Figures26(a) and 26(b) present the tests carried out of the avalanche effect, but with the least significant bit of the R channel altered at the end of one of the Lena images.Figure 26
Avalanche effect: (a) difference of channel R at the end of one of the Lena images; (b) difference of the cryptograms.
(a)(b)


### 4.1.7. Sensitivity of the Key

To verify whether the image can be recovered with different keys, Figure19(a) was encrypted with the keys of Table 8, generating the cryptogram of Figure 27(a), which was recovered correctly utilizing the same keys with which it was encrypted (Figure 27(b)). Recovery was also attempted by the alteration of x30 of 0.75749573951 to 0.75749573952, yielding as a result Figure 27(c). With the latter, it was proven that, on performing a small change in one of the keys, the image was unable to be recovered correctly.Table 8
Keys employed for encryption.
Diffusion IConfusionDiffusion IIx10=3.75846375846x20=2.58395739578x30=0.75749573951y10=1.37483648365y20=1.27490458294y30=−4.4839573944z10=7.29347658364z20=7.57395729493z30=−12.391038593a1=0.25783958392a2=0.15639204821a3=0.22491840583b1=5.74950385024b2=18.1749374935b3=15.1947394573c1=0.57583759382c2=0.16739275921c3=0.10385738593startdif1=15keyconf=3startdif2=89483—keyconf2=138495—Figure 27
Test of the sensitivity of the key.


### 4.1.8. Speed Tests

Algorithm speed was tested in an Omen 17 An101la laptop, with an Intel Core i7-8750 H 2.20 GHz processor, a Wester Digital Black 512 GB SSD hard drive, 16 GB RAM DDR4-2666 MHz, and the encryption algorithm was performed with Java language programming. Table9 presents a comparison of the encryption speed of the proposed system with other investigations.Table 9
Encryption time (seconds).
Image (pixels)Proposed[31][19][26][36]256 x 2560.1344380.06570.21512 x 5120.412850.24320.0070.2901.19


### 4.1.9. Key Space

The key space defines the number of different keys that can be used by a cryptosystem. The proposed algorithm uses six in diffusion technique Ix10,y10,z10,a1,b1,c1, another six when diffusion II is implemented x30,y30,z30,a3,b3,c3, and also, when implementing confusion, yet other six keys are used x20,y20,z20,a2,b2,c2. The precision of the floating-point number is 10−15; therefore, the key space is 10270≈2896. Additionally, the keys keyconf, keyconf2, startdif1,and stardif2 are implemented with a variable key space. Table 10 depicts a comparison of the space key of the proposed system with other investigations.Table 10
Secret key space.
Proposed[31][37][36][26][19][34][28]28964 variable keys 1027021282192220022982256101121058For the cryptosystem to be safe, there must be a key space greater than 2100 [38]; therefore, the proposed system will support a brute force attack.


### 4.1.10. Encryption Quality Analysis

To verify the quality of the encryption, we calculated the maximum deviation: to evaluate the deviation between the intensity of pixels of the original image and the cryptogram. If the value is high, the quality of the encryption is good. Irregular deviation allows to statistically evaluate the quality of the intensity of the pixels in the cryptogram. If it is high, the pixels are uniformly distributed. Deviation from ideality: this detects the probability of distribution of the pixels in the cryptogram. The closer to zero it is, the better the quality of the cryptogram [39]. (Table 11)Table 11
Encryption quality analysis.
Maximum deviationIrregular deviationDeviation from idealityReferenceRGBRGBRGB83,91281,294.587,629.532,10233,45338,1590.048520.047390.05227[28]5.0069 × 10436,47365,82645,90625,14027500.77340.54920.9882[29]36,43759,52670,23237,46860,53071,2380.0034637450.003829950.00369262Proposed


## 4.1.1. Histograms

In Figures20(a), 20(c), and 20(e), the histograms are presented of the RGB channels corresponding to Figure 19(a) and to the images of Figures 20(b), 20(d), and 20(f)), those of the cryptogram of Figure 19(e). As can be observed, there are no similarities in the distributions of the color frequencies between the original image and the cryptogram. That is, on observing the histograms corresponding to the cryptogram, it can be clearly seen that there is greater homogeneity in contrast with the originals; therefore, it is difficult for an attacker to find a relation between the original image and the cryptogram.Figure 20
Analysis of histograms: (a, c, e) original image of Lena red, green, and blue, respectively; (b, d, f) the histograms of the red, green, and blue channel cryptogram.
(a)(b)(c)(d)(e)(f)


## 4.1.2. Correlation

These permit the detection of the linear relation between two variables or images; this analysis yields anR correlation coefficient, which is found within the range of [−1 to 1]: the more it nears 1 and −1, the more both images are similar or alike if they yield these exact values. On the other hand, the nearer they are to 0, the greater the number of differences, or they are completely different if R=0.Figure21 presents the correlation diagram of the original image with respect to the cryptogram, and it can be observed that coefficient R=0.00000267625 is very close to 0; thus, it is more difficult for an attacker to attempt to find a relation between both of these.Figure 21
Diagram of the correlation between the original image vs. the cryptogram.In Figure22, the correlation is able to be observed of the original image vs. the decrypted one, which yields the result of R=1. Thus, the encrypted system guarantees integrity on recovering 100% of the information.Figure 22
Diagram of the correlation of the original image vs. the decrypted.In Table2, the results are shown of the correlation analysis. In the first column, the coefficient correlation is presented as generated on comparing the original image vs. the cryptogram; later, the original image was compared vs. the decrypted, with the results presented in column 2. As can be observed, our cryptosystem presents excellent results in comparison with those of other state-of-the-art cryptosystems.Table 2
Comparison of correlation coefficients.
CryptogramDecryptReference0.000002676251Proposed0.0028511[25]0.000686—[26]The correlation coefficient was calculated of 1,000 pairs of pixels taken at random, that is, the original image as well as the cryptogram horizontally, vertically, and diagonally, according to components R, G, and B. Figures23(a)–23(i) present the correlation diagrams generated from the original image, while those of Figures 24(a)–24(i) depict the distribution of the cryptograms.Figure 23
Correlation of pairs of the horizontal, vertical, and diagonal pixels of the original image according to the RGB channels.
(a)(b)(c)(d)(e)(f)(g)(h)(i)Figure 24
Correlation of horizontal, vertical, and diagonal pixels of the cryptogram according to the RGB channels.
(a)(b)(c)(d)(e)(f)(g)(h)(i)Table3 displays the correlation coefficients of Figures 23(a)–23(i) and of Figures 24(a)–24(i), which are compared with those of other investigations.Table 3
Coefficient of the horizontal, vertical, and diagonal correlation of pairs of adjacent pixels.
DistributionPlane imageEncrypted imageReferenceRGBRGBHorizontal0.9567——-0.0026——[27]Vertical0.9239——-0.0038——Diagonal0.8888——0.0017——Horizontal0.98430.97930.87840.0181−0.00670.0154[21]Vertical0.99280.98780.9204−0.00990.01260.0063Diagonal0.98100.97420.87170.00850.0127−0.0155Horizontal0.9335610.9056380.859151−0.00020268−0.00153669−0.00343206[28]Vertical0.96380.9464690.905638−0.000144000.00405293−0.00555131Diagonal0.9352890.9077030.860089−0.00309766−0.000400902−0.00026181Horizontal0.933380.90490.8597−0.0137−0.00490.0038[29]Vertical0.96410.94670.90610.0038−0.00080.0017Diagonal0.90740.88020.83830.0036−0.00120.0008Horizontal0.911170.899720.82821−0.0006840340.0000532805−0.000996056ProposedVertical0.942350.930020.870040.000861182−0.0009328790.00169Diagonal0.863730.845640.729950.00168−0.001−0.000996454Table4 presents a comparison of the horizontal, vertical, and diagonal distribution of channels R, G, and B, but now taking into account 5,000 pairs of adjacent pixels.Table 4
Coefficient of horizontal, vertical, and diagonal correlation of 5,000 pairs of adjacent pixels.
DistributionPlane imageEncrypted imageReferenceRGBRGBHorizontal0.9326670295864560.9222814932333490.8938252193918210.003535161409385−0.0097068716354860.018571551282381[30]Vertical0.9624087631313620.9546935078297540.934300708191352−0.0040763247259520.0053120320280560.010691355134514Diagonal0.9079660093985850.8804087760213110.863453990135567−0.041028497842243−0.008522993738987−0.017458909511577Horizontal0.97770.96040.91010.0135−0.0835−0.0170[31]Horizontal0.916690.860710.828290.00011123−0.000197324−0.000194282ProposedVertical0.9350.918650.87415−0.0001267170.000388285−0.000196329Diagonal0.874050.843510.78519−0.0000893574−0.000165072−0.000191976In the results of Tables3 and 4, it can be clearly observed that our system generates a correlation in the cryptograms that is much closer to 0, nearly null. Therefore, the proposed encryption technique renders the loss of the relation among adjacent pixels in the three directions.


## 4.1.3. Entropy

Entropy allows verification of the level of randomness or of how unpredictable the pixel values are in an image, which is the determination of the level of disorder of a cryptogram: the more the latter nears 8 or is equal to it, the better the processes of diffusion and confusion of the cryptogram and is more robust to an entropy attack, due to the degree of randomness of the cryptograms. Thus, this is unpredictable. Table5 depicts the entropy of the proposed system and compares it with other systems.Table 5
Entropy of different systems of encryption.
EntropyReference7.999[32]7.9988[33]7.997[31]7.997[34]7.997133[28]7.99654[29]7.9998[19]7.9988Proposed


## 4.1.4. NPCR (Number of Pixel Change Rate)

The NPCR permits the determination of the strength of the encryption with respect to a differential attack; that is, it determines the percentage of changes in the location of the pixels of two images. NPCR should yield a value near 100%, indicating that both images are very different.


## 4.1.5. UACI (Unified Average Changed Intensity)

The average is calculated of the differences in the intensity of the pixels of the two images. This should yield a result greater than 33%.NPCR and UACI were calculated with two cryptograms generated with nearly all of the same keys, with the exception of one carried out with a small change in the least significant decimal digit. NPCR results were obtained of above 99% and those of UACI were above 33%. Therefore, the proposed system takes as input a plane image and with a small change, generating a very different cryptogram. Table6 presents the results of this analysis.Table 6
NPCR and UACI of cryptograms encrypted with a small change in one of their keys.
AnalysisRGBReferenceNPCR99.655299.627799.588[27]UACI33.484633.413233.3441NPCR99.597199.600299.6368ProposedUACI33.389533.292533.5537In Table7, the result is presented of the analysis of the NPCR and UACI of the two cryptograms that were generated from the two images that were only differentiated because in one of these, the least significant bit of a red subpixel was changed; it also yielded NPCR> 99% and UACI> 33 as a result. Therefore, the proposed system is very sensitive to the plane image and would provide robustness when encountering a differential attack.Table 7
NPCR and UACI of cryptograms encrypted with a change in one of the subpixels.
AnalysisRGBReferenceNPCR99.6399.6099.61[31]UACI33.3133.3433.43NPCR99.565999.565899.5959[21]UACI33.282933.345933.3270NPCR99.642999.614099.6277[20]UACI33.393533.563733.4814NPCR99.612499.614099.6201[28]UACI33.423533.483833.5983NPCR99.598699.617099.6231ProposedUACI33.407433.564533.5042


## 4.1.6. Avalanche Effect

This analysis reflects the sensitivity of the encryption algorithms to a small change in the parameters (in the key or in the plane text) of the entry information, which should cause a great change in the cryptogram [35].This test was utilized to verify the differences between the two Lena images, in which, in one of these the least significant bit was modified in channel R in one of the initial pixels, and later compared with another without any change. Figure25(a) depicts the remainder between the two pixels and difference was able to be appreciated clearly. Figure 25(b) presents the remainder of the two pixels of the 2 cryptograms generated on encrypting the 2 Lena images, and it can be clearly seen that these are different. The proposed algorithm passes this test due to that the diffusion technique is applied on two occasions and, in addition, the pixels were taken into account on coding during confusion.Figure 25
Avalanche effect: (a) difference at the initiation of a Lena image; (b) differences in the cryptograms.
(a)(b)Figures26(a) and 26(b) present the tests carried out of the avalanche effect, but with the least significant bit of the R channel altered at the end of one of the Lena images.Figure 26
Avalanche effect: (a) difference of channel R at the end of one of the Lena images; (b) difference of the cryptograms.
(a)(b)


## 4.1.7. Sensitivity of the Key

To verify whether the image can be recovered with different keys, Figure19(a) was encrypted with the keys of Table 8, generating the cryptogram of Figure 27(a), which was recovered correctly utilizing the same keys with which it was encrypted (Figure 27(b)). Recovery was also attempted by the alteration of x30 of 0.75749573951 to 0.75749573952, yielding as a result Figure 27(c). With the latter, it was proven that, on performing a small change in one of the keys, the image was unable to be recovered correctly.Table 8
Keys employed for encryption.
Diffusion IConfusionDiffusion IIx10=3.75846375846x20=2.58395739578x30=0.75749573951y10=1.37483648365y20=1.27490458294y30=−4.4839573944z10=7.29347658364z20=7.57395729493z30=−12.391038593a1=0.25783958392a2=0.15639204821a3=0.22491840583b1=5.74950385024b2=18.1749374935b3=15.1947394573c1=0.57583759382c2=0.16739275921c3=0.10385738593startdif1=15keyconf=3startdif2=89483—keyconf2=138495—Figure 27
Test of the sensitivity of the key.


## 4.1.8. Speed Tests

Algorithm speed was tested in an Omen 17 An101la laptop, with an Intel Core i7-8750 H 2.20 GHz processor, a Wester Digital Black 512 GB SSD hard drive, 16 GB RAM DDR4-2666 MHz, and the encryption algorithm was performed with Java language programming. Table9 presents a comparison of the encryption speed of the proposed system with other investigations.Table 9
Encryption time (seconds).
Image (pixels)Proposed[31][19][26][36]256 x 2560.1344380.06570.21512 x 5120.412850.24320.0070.2901.19


## 4.1.9. Key Space

The key space defines the number of different keys that can be used by a cryptosystem. The proposed algorithm uses six in diffusion technique Ix10,y10,z10,a1,b1,c1, another six when diffusion II is implemented x30,y30,z30,a3,b3,c3, and also, when implementing confusion, yet other six keys are used x20,y20,z20,a2,b2,c2. The precision of the floating-point number is 10−15; therefore, the key space is 10270≈2896. Additionally, the keys keyconf, keyconf2, startdif1,and stardif2 are implemented with a variable key space. Table 10 depicts a comparison of the space key of the proposed system with other investigations.Table 10
Secret key space.
Proposed[31][37][36][26][19][34][28]28964 variable keys 1027021282192220022982256101121058For the cryptosystem to be safe, there must be a key space greater than 2100 [38]; therefore, the proposed system will support a brute force attack.


## 4.1.10. Encryption Quality Analysis

To verify the quality of the encryption, we calculated the maximum deviation: to evaluate the deviation between the intensity of pixels of the original image and the cryptogram. If the value is high, the quality of the encryption is good. Irregular deviation allows to statistically evaluate the quality of the intensity of the pixels in the cryptogram. If it is high, the pixels are uniformly distributed. Deviation from ideality: this detects the probability of distribution of the pixels in the cryptogram. The closer to zero it is, the better the quality of the cryptogram [39]. (Table 11)Table 11
Encryption quality analysis.
Maximum deviationIrregular deviationDeviation from idealityReferenceRGBRGBRGB83,91281,294.587,629.532,10233,45338,1590.048520.047390.05227[28]5.0069 × 10436,47365,82645,90625,14027500.77340.54920.9882[29]36,43759,52670,23237,46860,53071,2380.0034637450.003829950.00369262Proposed


## 5. Conclusions

In this article, a communication system is proposed that utilizes portable SBC devices and a server that performs detection, identification, and selective facial encryption, and the system implements diffusion and confusion techniques that, when applied individually, render cryptograms unrecognizable. However, to strengthen security, the techniques can be applied in layers, that is, the order in which diffusion or confusion is implemented and the number of times they are applied depends on the user. In fact, each time one of these techniques is used, the number of keys increases; thus, it is more difficult for an attacker to retrieve the original image. Based on the tests, it is recommended to apply the algorithm in the following order: diffusion I-confusion-diffusion II, for optimal encryption in matters of time and security. Furthermore, the algorithm considers the order and value of the pixels to encrypt; therefore, a small change in these or in the keys generates different cryptograms resistant to an avalanche attack, which not many cryptographic systems resist. Encryption time is longer than in other systems because it is preferred to provide more security when implementing a much larger key space, but if speed is preferred over security, only diffusion or confusion can be implemented.To verify the system’s robustness, a statistical analysis was carried out, in which it can be observed that the histograms generated from the cryptogram present excellent homogeneity in pixel distribution. In addition, by means of the diagrams of correlation and entropy, it was determined that the algorithm provides relevant disorder. Additionally, through NPCR and UACI, the differences were verified between the location and the intensity of the pixels, generating results of NPCR>99 and UACI>33; therefore, the system is robust on confronting differential attacks. Additionally, the cryptosystem does not obligate the implementation of a unique mathematical model; it is possible to utilize any model that generates chaotic orbits, which renders it highly sensitive to the encryption keys. For correct facial detection and identification, it is necessary to conduct the training using photographs of the persons to be identified and encrypted. The greater the number of photographs employed during this stage, the more accurate the recognition will be. In addition, the faces should not be superimposed or incomplete, and it is recommended that the photographs be controlled or semicontrolled in order to avoid that, at the time of detection and recognition, the position of the camera, the angle of the faces, the facial expressions, luminosity, and distance can affect. Also, when performing the recognition, this can affect whether persons have different makeup, hair tone, and natural aging. Therefore, it is recommended to train the system with different changes. During the tests carried out with the OpenCV Library, there have been cases in which persons are very similar and are confused with others. The library can also sometimes recognize some objects as faces. To correct this problem, the proposed system allows for manually selecting those one wants to encode. Another problem that can be generated is that the cryptograms overlap when the faces are close together.On utilizing the SBC, the use is reduced of hardware resources and it provides greater portability in that only when necessary is a superior database consulted in a remote server; also, the algorithm can be utilized in mobile devices. The communications system can be employed in police departments and military units to carry out searches for persons, for video surveillance, to safeguard the identity of persons in companies, for journalistic uses, and for uses in the social and communications media.



---

*Source: 8848356-2020-12-01.xml*