1 Introduction

Today, the internet is effective in every aspect of our lives. During the Covid-19 pandemic that we are currently experiencing, people had to stay at home more. Now, the internet is being used more intensively than ever before. All the transactions, such as shopping, banking, and remote working were carried out through the Internet. Apart from these, the use of social media platforms has increased very rapidly. Computers, mobile phones, smartwatches, devices connected to the Internet, security cameras in the areas we live in, and many other devices are all connected to the Internet. These devices send great amounts of data to different parts of the world with high-speed data transfers. Accessing a large amount of data over the Internet creates high-security risks. Many countries have enacted laws on the protection of personal data. In addition to personal data, the security of states is also crucial when sending data over the Internet. One way to securely send digital data over the Internet is encryption and the other is using steganography. The information to be encrypted can be plain text or an image.

Affine Algorithm is one of the encryption techniques used by cryptographers for plain text. However, it is possible to use AA for image encryption as well. Because the AA includes several operations including translation, scaling, rotation, and truncation, it can also be used for pixel scrambling in image encryption. However, despite these features, the use of AA alone for image encryption is not enough to make good encryption. Therefore, stronger encryption processes are required. Many researchers tried to develop stronger image encryption methods by using AA, LFSR, XOR encryption and other methods together. Lone et al. encoded the image using a random Affine encryption matrix, 2D Hénon, and a chaotic map [18]. Sayed et al. studied Affine encryption with six parameters [25]. Wang et al. combined AA encryption with the zigzag method [29]. They represented secure image encryption with pixel and AA encryption in this study [30]. Chen et al. proposed an encryption algorithm using the AA and Fractional Fourier Encryption [6]. Multilayer resilient color image encryption with random matrix AA was studied [24]. Khan et al. used an S8 permutation of double-AA in S-boxes and a nonlinear Lorentz dynamics system for image encryption [11]. Deb and Bhuyan proposed a new medical image encryption system using a special nonlinear filter function based on Linear Feedback Shift Register (LFSR) [8]. Momeni et al. proposed color image encryption method using LFSR by three dimensional permutation and substitution operations [20]. Masood et al. proposed a lightweight chaos-based medical image encryption scheme using random shuffling and XOR operations [19]. Thinnukool et al. double encryption algorithm using trigonometric chaotic map and XOR of an image [28].

In this study, a new color image encryption algorithm is proposed using LFSR technique known as a random number generator and XOR encryption together with AA, and this algorithm is called Improved Affine Algorithm (IAA). In image encryption, the LFSR is used for key generation. The XOR encryption method is preferred because it is a simple and complex structure. The XOR encryption method is used with LFSR keys.

The main contributions of this study can be summarized as follows:

  • In this study, the IAA algorithm developed for color image encryption is used. The user selects ten different keys for AA encryption. The original image is split into three channels: R, G, and B. The image is encrypted with AA using four keys based on pixel locations and six keys based on pixel values.

  • The rows and columns of the image are encrypted using the LFSR 256-key and XOR encryption.

  • The proposed algorithm is tested with the Histogram, MSE, PSNR, UACI, NPCR, and Entropy. A comprehensive analysis is provided by comparing IAA with other encryption algorithms in the literature. The IAA achieves remarkable improvement and outperforms other encryption algorithms compared in this study.

The content provided in the rest of this paper is organized as follows: In Section 2, Affine Algorithm, Linear Feedback Shift Register, and XOR encryption with LFSR are briefly explained. Section 3 describes the proposed encryption algorithm in detail. In Section 4, the experiments and comparisons are presented, and the results are discussed. Finally, conclusions and future works are given in Section 5.

2 Background

Affine Algorithm (AA), Linear Feedback Shift Register (LFSR), and XOR encryption with the LFSR approach is examined in this section. Following that, the proposed algorithm is examined.

2.1 Affine algorithm

Affine cipher is a type of classical substitution cipher used in cryptography. It was initially created to encrypt a set of 26 English characters. AA is a widely used and well-known encryption method. AA is a multi-key encryption algorithm. The structure of AA is more complex and secure than that of single-key encryption algorithms [18, 25, 29, 30]. AA is used for both text encryption and image decryption. In this study, AA is used for image encryption. For MxN pixel sizes images, AA formula is shown in Eq. (1) and AA decryption formula is shown in Eq. (2).

$$ \mathrm{y}=\mathrm{ax}+\mathrm{b}\ \left(\operatorname{mod}\ \mathrm{N}\right) $$
(1)
$$ \overline{\mathrm{y}}={\mathrm{a}}^{-1}\left(\mathrm{x}-\mathrm{b}\right)\ \left(\operatorname{mod}\ \mathrm{N}\right) $$
(2)

where y is the encryption operation and \( \overline{y} \)is the decryption operation. The keys used in AA (Eq. 1 and Eq. 2) are denoted as the a-key and the b-key. For decryption, the Greatest Common Divisor (GCD) must be equal (a, N) = 1. Consequently, the a-key should not have a common divisor of N and the b-key should be selected from 0 to N-1.

2.2 Linear feedback shift register

A perfectly random series of integers is required when encrypting images with LFSR [1]. After all subsequent numbers have been generated, the first numbers are traced. During this process, the digits are carried over the register. The bits are shifted one position to the left, and the shifted bit and the bit previously at a particular step position in the register replace the released bit. The length of the LFSR is [q0, q1, q2, ..., qj], where q is the number of circuits and j is the number of registers in the LFSR and the flip-flop circuits can be increased or decreased arbitrarily. It is represented by the clock (c) of the LFSR, where (ci) is the number of records in the LFSR.

In LFSR, the first numbers are randomly generated. The first numbers are used to generate the second numbers with the XOR operation. To generate the second numbers, the first numbers are shifted in the register. While shifting, the value of the q0 is shifted to the q1. The value of q0 is then XORed by the value of the q1 and the result obtained is used as the new value of the q2. The identical actions are performed again and again until the last number is generated. In Fig. 1, the LFSR shift operations and operations to generate new numbers are specified with colors and the colors can be used to track the shifts.

Fig. 1
figure 1

An example of the LFSR in a numerical procedure

In Fig. 1, the LFSR is 3 bits long and is represented by q0, q1, and q2. The LFSR time is represented by ci. In this example, the q0 and the q1 are created randomly (q0 = 0 and q1 = 1). The initial time (cinitial) is the result of the XOR operation of the q0 and the q1 ((cinitial) q0 = 0 ⊕ q1 = 1 → q2 = 1). Then, the q0 on cinitial is shifted to q1 on c1, and the green color is used to describe this operation on cinitial and c1. In c1, q0 and q1 are XORed, and q2 is updated as a result ((c1) q0 = 1 ⊕ q1 = 0 → q2 = 1). After that, q0 on c1 is shifted to q1 on c2 and the blue color is used to describe this operation on c1 and c2. To produce ten distinct integers, nine feedback shift operations (c9) are conducted. All operations can be understood by following the colors. The LFSR is commonly used to generate encryption keys. Key generation using LFSR is used in various encryption techniques in the literature.

2.3 XOR encryption with LFSR

XOR encryption is a text and image encryption algorithm. Random keys are generated by LFSR, and the key and pixel values are encrypted in XOR encryption. The XOR operation is preferred by many cryptographers because it is more secure. The LFSR is used to generate the key in the XOR encryption. The flowchart of encryption algorithms with XOR encryption with LFSR is shown in Fig. 2.

Fig. 2
figure 2

Combination of XOR encryption with LFSR

In Fig. 2, XOR encryption with LFSR, the color image is selected first. In LFSR, random numbers are first used for key generation, and LFSR is tuned to generate keys for each column. New pixel values are found with random numbers. After shuffling the pixels, a row encryption image is obtained. The decryption step uses the same key as the encryption step. For column encryption, a sequence of random numbers is generated, which is to be converted into a matrix. This method rearranges or swaps the pixel values of the image by using the random matrix. Column encryption is studied on the row-encrypted image. As a result, the image is encrypted using XOR encryption with LFSR encryption methods. Encryption is column-wise and row-wise, and multiple keys are used.

3 Proposed approach

In this study, the images named Lena, Baboon, Airplane, and Pepper are used. The size of each image is 256 × 256 pixels. For this reason, in this study, explanations will be made for images with a resolution of 256 × 256 pixels from now on. The algorithm is applied to the RGB channels of the color image separately. The algorithm is developed in three steps: (i) Pixel Locations Encryption using AA, (ii) Pixel Values Encryption using AA, (iii) XOR encryption with LFSR.

  • (i) Pixel locations encryption using AA

The plain image is split into three RGB channels. The algorithm is applied to each RGB channel of the color image separately. The four keys: a1, b1, a2, and b2 are used in this step. Since the size of each image is 256 × 256 pixels, b1 and b2 should be chosen between 0 and 255. a1, and a2 should be chosen so that GCD(a,256) = 1. In this stage, firstly Pixel locations of the image are encrypted using Eq. (1) for the a1 and b1 keys. Secondly, Pixel locations of the image are encrypted using Eq. (1) for a2 and b2 keys. The encryption processes are visualized in Fig. 3.

Fig. 3
figure 3

AA encryption for the color Lena image’s pixel locations

The original image is shown in Fig. 3a and the encryption of the original image is shown in Fig. 3b by encrypting pixel positions with two keys. Finally, the pixel locations are encrypted a second time using two keys, as shown in Fig. 3c.

  • (ii) Pixel values encryption using AA

The pixel values of the image in each channel of the color image are encrypted with AA, and the encryption is performed with Eq. (1). A total of six keys are used for pixel value encryption. The a3, b3 keys are used for the R channel, the a4, b4 keys are used for the G channel, and the a5, b5 keys are used for the B channel. In this step, a total of six keys are utilized for encryption.

In Fig. 4, the image is divided into RGB channels and AA encryption is applied to the image pixel values with a total of six keys: two keys for the R channel, two keys for the G channel, and two keys for the B channel. The encrypted image is concatenated after the channels are encrypted. Encrypting channels individually and with different keys improved the security.

  • (iii) XOR encryption with LFSR

Fig. 4
figure 4

AA pixel values encryption for RGB channels

LFSR generates a total of 256 different keys for a 256 × 256 image. LFSR key is used to XOR encrypt each pixel of the image. At this stage, XOR encryption is applied twice. In the first step, the rows of the image are encrypted with XOR using the key generated with LFSR. In the second step, the columns of the image are encrypted with XOR. Then, all the operations are repeated and the encryption process is completed. Therefore, a strongly encrypted image is obtained with IAA.

The image is encrypted and decrypted using the same keys. The decryption procedure occurs in the opposite direction of the encryption procedure. The block diagram of the image encryption algorithm is shown in Fig. 5. The block diagram of the image decryption algorithm is shown in Fig. 6. The procedures of the encryption algorithm are shown in Fig. 7 whereas the procedures of the decryption algorithm are shown in Fig. 8.

Fig. 5
figure 5

Block diagram of the encryption of the IAA

Fig. 6
figure 6

Block diagram of the decryption of the IAA

Fig. 7
figure 7

The image encryption procedures of the IAA

Fig. 8
figure 8

The image decryption procedures of the IAA

4 Results and analysis

The proposed algorithm is tested with the Histogram, MSE, PSNR, UACI, NPCR, and Entropy analyses. After the encryption tests, the structural content is examined to determine the best algorithm for image encryption and the success of the proposed algorithm is compared with other encryption algorithms. It is explained in detail in this section.

The content provided in the rest of this section is organized as follows: In Section 4.1, Experimental Analysis is briefly summarized. In Section 4.2, the proposed algorithm is compared using the Histogram, MSE, PSNR, NPCR, UACI, and Entropy analyses. The experiments and comparisons are presented, and the results are discussed. Tests and analyses of the proposed algorithm are performed in Section 4.3.

4.1 Experimental analysis

In this study, the images named Lena, Baboon, Airplane, and Pepper are used. The size of each image is 256 × 256 pixels. Image encryption is performed with ten different keys. The pixel keys are represented by a1, b1, a2, and b2, and the RGB keys are represented by a3, b3, a4, b4, a5, and b5. For LFSR, “11,011,001” is selected as the initial value and set to 8 bits (0 to 255). The keys used in this study are shown in Table 1. The original images, the encrypted images, and the decrypted images are shown in Table 2.

Table 1 Keys determined for IAA
Table 2 The original image, the encrypted image, and the decrypted image with IAA

Table 2 shows that the encryption and decryption operations are successful. The performance of the proposed algorithm is analyzed in the following section.

4.2 Experimental results

The Histogram, MSE, PSNR, NPCR, UACI, and Entropy analyses are explained in this section. Finally, the Histogram, MSE, PSNR, NPCR, UACI, and Entropy analyses are utilized to evaluate the performance of the proposed algorithm.

4.2.1 Histogram analysis

The distribution of the pixel intensities of an image is represented by the Histogram. Also, the analysis of the Histogram shows the probability of hacker-encrypted images being hacked by using frequency data and statistics. The quality of the algorithm used is shown by the homogeneous distribution of the Histogram of the encrypted image [22].

4.2.2 Mean square error and peak signal to noise ratio

The original and encrypted images are compared with Mean Square Error (MSE) [2]. MSE is the mean squared error estimate used to compare possible image differences. In general, the lower the value of MSE, the better the results. In this study, the success of the encrypted image is examined using the MSE value. The original image is represented by IR, G, B, the decrypted image by \( {\overset{\prime }{I}}_{R,G,B} \), the image size by MxN, ∆x, and ∆y by the pixel size. MSE formula is as shown in Eq. (3).

$$ {MSE}_{R,G,B}\kern0.5em =\kern0.5em \frac{1}{M\times N}\ \sum \limits_{i=1}^{M-1}\sum \limits_{j=1}^{N-1\ }\left[{\left|\ {I}_{R,G,B}\left( m\varDelta x, n\varDelta y\right)-{\overset{\prime }{I}}_{R,G,B}\ \left( m\varDelta x, n\varDelta y\right)\ \right|}^2\right] $$
(3)

Peak Signal to Noise Ratio (PSNR) shows similarities between images. After encrypting the image, PSNR value is used to measure the image deformations [26]. PSNR value is low after successful encryption. PSNR is expressed in decibels (dB) [4]. PSNR is calculated together with MSE values. PSNR test is performed to measure the security of the encrypted images. Achieving a high score on the PSNR test indicates a successful encryption process. The formula for PSNR is shown in Eq. (4).

$$ PSNR\left({}^{\prime }{I}_{R,G,B,}{I}_{R,G,B}\right)=10{\log}_{10}\left(\frac{\left(M-1\right)\times \left(N-1\right)}{\Sigma_{\forall \mathrm{M},\mathrm{N}}{\left[{\overset{\prime }{I}}_{R,G,B}(M.N)-{I}_{R,G,B}\left(M,N\right)\right]}^2}\right) $$
(4)

4.2.3 Number of pixels change rate and unified average changing intensity

Differential attack analysis is performed to detect changes in encrypted images. The hackers are unable to make any meaningful association with the original images based on a small change in the encrypted images because the small change in the original images is created a large change in the encrypted images. The Number of Pixels Change Rate (NPCR) and Unified Average Change Intensity (UACI) are commonly used to measure the effectiveness of this type of attack. NPCR, pixel change with the original image comparison of the encrypted image shows the change in several pixels of the encrypted image and the rate. UACI rate, the encryption technique against various attacks, is defined as the resistance ratio. The average density difference between the original image and the encrypted image is UACI value [23]. Eq. (5) represents the calculation of the NPCR and Eq. (6) represents the calculation of UACI.

$$ {NPCR}_{R,G,B}=\frac{\sum_{i=1\kern0.5em j=1}^{i=M\ j=N}\kern0.75em {D}_{R,G,B}\left(i,j\right)}{M\times N}\times 100\%\kern2.25em {D}_{R,G,B}\left(i,j\right)=\kern0.5em \left\{\begin{array}{c}0\kern1.25em \mathrm{if}\kern0.5em {I}_{R,G,B}={\overset{\prime }{I}}_{R,G,B}\\ {}1\kern1.25em \mathrm{if}\kern0.5em {I}_{R,G,B}\ne {\overset{\prime }{I}}_{R,G,B}\ \end{array}\right. $$
(5)
$$ {UACI}_{R,B,G}=\frac{1}{M\times N}\ \left[{\sum}_{i=1\kern0.5em j=1}^{i=M\ j=N}\frac{\left|{\overset{\prime }{I}}_{R,G,B}\left(i,j\right)-\kern0.5em {I}_{R,G,B}\left(i,j\right)\right|}{255}\right]\times 100\% $$
(6)

where M and N are the width and height of the image. The original image is represented by I, the decrypted image by \( \overset{^{\prime }}{I} \), the image size by MxN, The difference array D(i, j) is defined as follows: if \( \overset{\acute{\mkern6mu}}{I} \)=I, D(i, j) = 0; otherwise, D(i, j) = 1 [3].

4.2.4 Entropy analysis

Entropy is a significant property that represents the degree of disorder in a system. Entropy is used to calculate the probability of obtaining the original image without knowing the key [5, 14]. Eq. (7) represents the calculation of the value of the Entropy [9].

$$ \mathrm{H}\left(\mathrm{m}\right)={\sum}_{\mathrm{i}=0}^{\kern0.5em {2}^{\mathrm{N}}-1}\ \mathrm{P}\left({\mathrm{m}}_{\mathrm{i}}\right)\times \kern0.5em {\log}_2\left(\frac{1}{\mathrm{P}\left({\mathrm{m}}_{\mathrm{i}}\right)}\right) $$
(7)

where N is the number of bits to represent a symbol mi ∈ m. Entropy is measured in bits, where P(mi) is the probability of the symbol mi and the log is the logarithm to base 2. For a source emitting 2N symbols at random, H(m) = N is the Entropy value. The entropy value result is expected to be about 8 (H(m) ≈ 8).

4.3 Test and analysis

In this section, MSE, PSNR, UACI, NPCR, and Entropy values are performed to prove that IAA is a successful encryption algorithm. First, the Histograms of the images are analyzed. A homogeneous structure in the encrypted image’s histogram is required for effective encryption. The proposed algorithm is used for the encryption of the color images of Lena, Baboon, Airplane, and Pepper. Table 3 shows the original image histogram, the encrypted image histogram, and the decrypted images. Table 3 compares the histograms of the original image and the decrypted image, and the encrypted images of the Histograms are appeared to be fairly evenly distributed. As a result, IAA is recognized as an efficient form of cryptography.

Table 3 Histogram analysis of the images

MSE, PSNR, UACI, and NPCR metrics are computed to measure success and resistance to attack, and all results are obtained for each RGB channel of images. PSNR is measured in decibels (dB). UACI and NPCR are calculated in percentages (%). In Table 4, MSE, PSNR, UACI, and NPCR values of RGB channels of images are compared to show the performance of the proposed encryption algorithm. In Table 4, MSE results prove that the original image is obtained after decryption with only minor errors. PSNR results show that IAA encryption is secure for the images. The suggested encryption algorithm is successful in differential attack analysis if NPCR is above 99% and UACI is above 33% [14]. The average NPCR value for all color test images considered in this study is 99.67% and the average UACI value is 33.58%. UACI and NPCR results show that encryption is effective, and the keys are secure. All tests show that IAA’s image encryption algorithm and image decryption algorithm are extremely secure.

Table 4 MSE, PSNR, NPCR and UACI results of the proposed algorithm

Table 5 compares the MSE results of the proposed algorithm to the results of other image encryption algorithms available in the literature. IAA outperforms the other two algorithms in MSE results. Table 6 shows UACI and NPCR results obtained for Lena, Baboon, Airplane, and Pepper images of the proposed algorithm and various image encryption algorithms in the literature.

Table 5 MSE results of the proposed algorithm and other encryption algorithms
Table 6 NPCR and UACI results of the proposed algorithm and other encryption algorithms

The Entropy values of RGB channels of images are compared to show the performance of the proposed encryption algorithm. Table 7 shows the entropy results of the proposed algorithm. Table 8 shows the proposed algorithm and the results of other algorithms published in the literature.

Table 7 Entropy of the proposed algorithm
Table 8 The Entropy of the encrypted images

The minimum value of information Entropy analysis is zero, whereas the maximum value is eight [15]. Table 7 shows the RGB channel information entropy values for the proposed algorithm. Entropy analysis of the purposed algorithm is calculated as H(m) ≈ 8. The entropy analysis of the suggested algorithm is compared with the entropies of various encryption algorithms in Table 8.

Table 8 shows that IAA is a more highly secure cryptographic procedure than other encryption algorithms. All tests and analyses proved that IAA is a safe encryption algorithm. As a consequence, the proposed algorithm is extremely robust against Entropy attacks on image predictions.

5 Conclusion

In this study, a novel color image encryption algorithm named Improved Affine Algorithm (IAA) is developed. IAA is performed in three procedures. In the first step, the plain image is split into three channels: R, G, and B. The RGB channel pixel locations are encrypted two times with four different keys using Affine Algorithm (AA). In the second step, the RGB channel pixel values are encrypted separately with a total of six different keys using AA. Finally, the rows and columns of the image are XOR encrypted with 256 keys using LFSR. The decryption procedure occurs in the opposite direction of the encryption procedure. The proposed algorithm is used for the encryption of the color images of Lena, Baboon, Airplane, and Pepper. IAA has successfully performed encryption operations and decryption operations. Further, the Histogram, MSE, PSNR, UACI, NPCR, and Entropy values are measured the purpose algorithm’s performance. The experimental results are compared to other encryption algorithms. The analyses and comparisons show that the proposed encryption algorithm is highly secure against various attacks.