Introduction to chaotic image encryption and decryption
Design and application of image encryption algorithm based on chaotic system
Ii. Introduction to Arnold scrambling image encryption and decryption
Network has become the main platform for us to transfer information, providing us with many convenient at the same time, there are also some security problems, especially some important information transmission. If the information is encrypted before transmission, the transmitted information can be protected to some extent. As an important information resource, digital images are playing an increasingly important role in people’s lives [1]. Therefore, the encryption of digital images is an important subject worthy of study. This paper introduces an image encryption and decryption algorithm based on Arnold transform.
1 Arnold transformThe point (x, y) on N*N image is transformed into (x ‘, y ‘) through the following transformation, as shown in Equation (1), which is called Arnold transformation. Through the transformation formula, it can be found that the essence of the transformation is the transformation of the position of the point, and this transformation ensures that the point before and after the transformation keeps a one-to-one correspondence relationship.If the output of one transformation is taken as the input of the next transformation, it is an iterative transformation as shown in Equation (2). When the scrambling effect of the first transformation is not good, the iterative transformation is often needed to obtain better scrambling effect. 2 image encryption and decryption based on Arnold transformImage encryption, also known as image scrambling, is to clutter and diffuse the pixels of an image, so that the encrypted image cannot obtain effective information visually. Spatial encryption is a common method, which is divided into spatial scrambling and sequence encryption. Spatial scrambling is to transform pixel coordinates to make them chaotic and restore the original pixel coordinates during decryption. Image encryption can not only be used as an independent information hiding method, but also as a preprocessing of image watermarking in digital watermarking technology.
The encrypted image can be grayscale image or color image. If it is grayscale image, the grayscale value of each point needs to be brought to the new coordinate point; if it is color image, the RGB value of each point needs to be brought to the new coordinate point. The encrypted image in this paper is a color image, so first save the RGB value at the original image point (x, Y), then use Arnold transform to change the position of point (x, y) to (x ‘, Y ‘), and bring the RGB value at the original image point (x, Y) to (x ‘, Y ‘). We use 256*256 color images as the original image, as shown in figure 1a. On the platform of Visual Studio2008, formula (1) is used to perform an Arnold transformation on the original image, and the effect after transformation is shown in figure 1b.
As can be seen from Figure 1, much information will still be left after one Arnold transform on the image, so it is difficult to obtain any valuable information visually after five transformations (see Figure 2b), which plays a role of image encryption visually. The number of simultaneous transformations can often be used as a key to improve security to a certain extent.FIG. 1 The original image and the result of an Arnold transformFigure 2 Results of the 2nd and 5th Arnold transform However, the encryption at this time is not completely reliable. If Arnold transform is known to be used as the encryption method, the original image can be decrypted after several transformations through the violent solution method. Therefore, in general, we often need to add key (KU, KV) into Arnold transform to improve security, and the formula is as follows:When the image needs to be decrypted, it should be decrypted according to the one-to-one correspondence between pixels in the encrypted image and pixels in the original image. Therefore, the process of image decryption is as follows: According to the coordinates of pixels in the original image (X, Y), the coordinates of pixels in the new image (X ‘, Y ‘) can be calculated according to the Arnold transformation. Get the RGB value of the new pixel (x ‘, y ‘) and return it to (x, y). According to the number of transformations used in the encryption process, the original image can be restored by repeating the above process for the corresponding number of times during decryption (see Figure 3).
3 image encryption based on 3D Arnold transformThe above mentioned image scrambling is achieved by shuffling the position of pixels, while the color component value of the image remains unchanged. Therefore, in order to improve the encryption effect, we can encrypt the image by changing the value of RGB color component on the premise that the pixel position is chaotic. The following THREE-DIMENSIONAL Arnold transform (as shown in Equation 4) is used to change the RGB component values.The image after Arnold transformation is taken as the original image. On this basis, the RGB of each pixel is disturbed by the above formula, and the results are obtained as shown in FIG. 4. By combining the two encryption methods, the security of encrypted image is further improved. The value in Formula 4 can be changed accordingly, and the number of transformations can be used as the key to improve security.Figure 3. Result of the fifth Arnold transform, encrypted image after recoveryFigure 4. Result of the first Arnold transform, encrypted image after RGB disturbance
Three, some source code
Function jiami % NOTE: please modify testImgName to test different input images, support grayscale and RGB image % testImgName ='lena';
% testImgName = 'lena_color';
% testImgName = 'color0';
% testImgName = 'lena16x16';
% testImgName = 'gray32x32';
% testImgName = 'gray2';
testImgName = 'pepper_gray';
% testImgName = '1Pixel';
img = imread(strcat(testImgName, '.png')); [w h rgb] = size(img); % Chaos map pre-iteration times, Logistic map initial value x0, mu, Arnold scrambling times Key = [128.0.7532.3.8793.2]; % NOTE: Modify encryptCount to test different encryptCount counts2; % imgEncrypted = img;for i = 1 : encryptCount
imgEncrypted = encrypt(imgEncrypted, Key);
end
disp('# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #'); % information entropy calculationif rgb == 3ImgR = imgEncrypted(:, :,1);
imgG = imgEncrypted(:, :, 2);
imgB = imgEncrypted(:, :, 3);
entropyR = informationEntropy(imgR);
entropyG = informationEntropy(imgG);
entropyB = informationEntropy(imgB);
disp(strcat('-- -- -- -- -- -, testImgName, ', encryption times are :', num2str(encryptCount), Information entropy R:, num2str(entropyR), ',G:', num2str(entropyG), ',B:', num2str(entropyB), '-- -- -- -- -- -));
imgR = img(:, :, 1);
imgG = img(:, :, 2);
imgB = img(:, :, 3);
entropyR = informationEntropy(imgR);
entropyG = informationEntropy(imgG);
entropyB = informationEntropy(imgB);
disp(strcat('-- -- -- -- -- -, testImgName, Original graph information entropy R:, num2str(entropyR), ',G:', num2str(entropyG), ',B:', num2str(entropyB), '-- -- -- -- -- -));
else% grayscale image % statistical output figure;if rgb == 3% color image subplot(4.2.1);
imshow(uint8(img));
title('clear');
subplot(4.2.2);
imshow(imgEncrypted);
title('ciphertext');
imgR = img(:, :, 1);
imgG = img(:, :, 2);
imgB = img(:, :, 3);
subplot(4.2.3);
imhist(uint8(imgR));
title('Plaintext R component histogram');
subplot(4.2.5);
imhist(uint8(imgG));
title('Plaintext G component histogram');
subplot(4.2.7);
imhist(uint8(imgB));
title('Plaintext B component histogram');
imgEncryptedR = imgEncrypted(:, :, 1);
imgEncryptedG = imgEncrypted(:, :, 2);
imgEncryptedB = imgEncrypted(:, :, 3);
subplot(4.2.4);
imhist(imgEncryptedR);
title('Ciphertext R-component histogram');
subplot(4.2.6);
imhist(imgEncryptedG);
title('Ciphertext G component histogram');
subplot(4.2.8);
imhist(imgEncryptedB);
title('Ciphertext B-component histogram');
else% grayscale image subplot(2.2.1);
imshow(uint8(img));
title('clear');
subplot(2.2.2);
imshow(uint8(imgEncrypted));
title('ciphertext');
subplot(2.2.3);
imhist(uint8(img));
title('Plaintext histogram');
subplot(2.2.4);
imhist(uint8(imgEncrypted));
title('Ciphertext histogram'); End % Image damage test % salt and pepper noise delta =0.02;
imgEncrypted_Noise_Salt = imnoise(imgEncrypted, 'salt & pepper', delta);
imgDecrypted_Noise_Salt = imgEncrypted_Noise_Salt;
for i = 1: encryptCount imgDecrypted_Noise_Salt = decrypt(imgDecrypted_Noise_Salt, Key); end imgDecrypted_Noise_Salt = uint8(imgDecrypted_Noise_Salt); ImgEncrypted_Noise_Gaussian = imnoise(imgEncrypted,'gaussian', delta);
imgDecrypted_Noise_Gaussian = imgEncrypted_Noise_Gaussian;
for i = 1: encryptCount imgDecrypted_Noise_Gaussian = decrypt(imgDecrypted_Noise_Gaussian, Key); % crop imgEncrypted_Croped = crop(imgEncrypted); imgDecrypted_Croped = imgEncrypted_Croped;for i = 1 : encryptCount
imgDecrypted_Croped = decrypt(imgDecrypted_Croped, Key);
end
imgDecrypted_Croped = uint8(imgDecrypted_Croped);
figure;
subplot(3.3.1); imshow(imgEncrypted); title('Encrypted image');
subplot(3.3.2); imshow(imgEncrypted_Noise_Salt); title(strcat('(1) pepper noise ρ=', num2str(delta)));
subplot(3.3.3); imshow(imgDecrypted_Noise_Salt); title('(1) Decrypt image ');
subplot(3.3.5); imshow(imgEncrypted_Noise_Gaussian); title(strcat((2) Gaussian noise μ=0,σ=', num2str(delta)));
subplot(3.3.6); imshow(imgDecrypted_Noise_Gaussian); title('(2) Decrypt image ');
subplot(3.3.8); imshow(imgEncrypted_Croped); title('(3) 1/16 shear');
subplot(3.3.9); imshow(imgDecrypted_Croped); title('(3) Decrypt image '); % plaintext sensitivity % color image gray = imgPlain(w, h,1);
% bin = dec2bin(gray);
gray = bitxor(gray, 1);
imgPlain(w, h, 1) = gray;
else% gray = imgPlain(w, h); % bin = dec2bin(gray); gray = bitxor(gray,1);
imgPlain(w, h) = gray;
end
imgEncrypted1 = imgPlain;
for i = 1: encryptCount imgEncrypted1 = encrypt(imgEncrypted1, Key); End % Key sensitivity Key2 = [128.0.753200000000001.3.8793.1];
imgDecryptedWithKey2 = imgEncrypted;
for i = 1 : encryptCount
imgDecryptedWithKey2 = decrypt(imgDecryptedWithKey2, Key2);
end
figure;
title(strcat(num2str(encryptCount), 'round encryption'));
subplot(2.2.1); imshow(img); title('clear');
subplot(2.2.2); imshow(imgEncrypted); title('ciphertext');
subplot(2.2.3); imshow(imgDecrypted); title('Decryption result of original key');
subplot(2.2.4); imshow(imgDecryptedWithKey2); title('Decryption result of key change by one bit');
disp(strcat('-- -- -- -- -- -, testImgName, ', encryption times are :', num2str(encryptCount), ', key sensitivity analysis ------'));
NPCR(imgEncrypted, imgEncrypted2, 'Key changed by 1 value');
UACI(imgEncrypted, imgEncrypted2, 'Key changed by 1 value'); % correlation relationType =2;
relationCount = 1024;
if rgb == 3ImgEncryptedR = imgEncrypted(:, :,1);
imgEncryptedG = imgEncrypted(:, :, 2);
imgEncryptedB = imgEncrypted(:, :, 3);
imgRrelation = relation(imgR, relationType, relationCount, strcat('-- -- -- -- -- -, testImgName, ', the plaintext R component '));
imgGrelation = relation(imgG, relationType, relationCount, strcat('-- -- -- -- -- -, testImgName, ', G component of plaintext '));
imgBrelation = relation(imgB, relationType, relationCount, strcat('-- -- -- -- -- -, testImgName, ', B component of plaintext '.));
imgEncryptedRrelation = relation(imgEncryptedR, relationType, relationCount, strcat('-- -- -- -- -- -, testImgName, ', ciphertext R component '));
imgEncryptedGrelation = relation(imgEncryptedG, relationType, relationCount, st
subplot(2.3.1);
plot(imgRrelation(1, :), imgRrelation(2, :).'. ');
axis([0 256 0 256]);
title('Horizontal correlation of plaintext R component gray value');
subplot(2.3.2);
plot(imgGrelation(1, :), imgGrelation(2, :).'. ');
axis([0 256 0 256]);
title('Plaintext G component');
subplot(2.3.3);
plot(imgBrelation(1, :), imgBrelation(2, :).'. ');
axis([0 256 0 256]);
title(Plaintext B component);
subplot(2.3.4);
plot(imgEncryptedRrelation(1, :), imgEncryptedRrelation(2, :).'. ');
axis([0 256 0 256]);
title('Horizontal correlation of ciphertext R-component gray values');
subplot(2.3.5);
plot(imgEncryptedGrelation(1, :), imgEncryptedGrelation(2, :).'. ');
axis([0 256 0 256]);
title('Ciphertext G component');
subplot(2.3.6);
plot(imgEncryptedBrelation(1, :), imgEncryptedBrelation(2, :).'. ');
axis([0 256 0 256]);
title('Ciphertext B component');
else% gray image figure; subplot(2.1.1);
plot(imgrelation(1, :), imgrelation(2, :).'. ');
axis([0 256 0 256]);
title('Horizontal correlation of plaintext gray values'); xlabel('Pixel gray value of position (I,j)'); ylabel('Pixel gray value of position (I +1,j)');
subplot(2.1.2);
plot(imgEncryptedrelation(1, :), imgEncryptedrelation(2, :).'. ');
axis([0 256 0 256]);
title('Horizontal correlation of ciphertext gray values'); xlabel('Pixel gray value of position (I,j)'); ylabel('Pixel gray value of position (I +1,j)'); Function imgEncrypted = encrypt(img, Key) img = encrypt(img, Key)double(img);
[w h rgb] = size(img);
if rgb == 3% color imageelseImg = logisticReplace(img, Key(3), Key(2), Key(1)); % % 3d scrambling L =floor(lengthImg ^ (1 / 3));
lengthCube = L ^ 3;
img = reshape(img, lengthImg, 1);
Cube1 = reshape(img(1: lengthCube), L, L, L); Cube1 = triplePermution(Cube1); % transform to 2d image imgEncrypted(1 : lengthCube, 1) = reshape(Cube1, lengthCube, 1);
imgEncrypted(lengthCube + 1 : lengthImg, 1) = img(lengthCube + 1 : lengthImg, 1); imgEncrypted = reshape(imgEncrypted, w, h); % Arnold = ution(imgEncrypted, Key(4)); end imgEncrypted = uint8(imgEncrypted); Function imgDecrypted = decrypt(img, Key) img =double(img);
[w h rgb] = size(img);
if rgb == 3% color imageelseImg = solution (img, Key(4)); LengthImg = w * h; L =floor(lengthImg ^ (1 / 3));
lengthCube = L ^ 3;
img = reshape(img, lengthImg, 1);
Cube1 = reshape(img(1: lengthCube), L, L, L); Cube1 = tripleDePermution(Cube1); % convert to 2d image imgDecrypted(1 : lengthCube, 1) = reshape(Cube1, lengthCube, 1);
imgDecrypted(lengthCube + 1 : lengthImg, 1) = img(lengthCube + 1 : lengthImg, 1); imgDecrypted = reshape(imgDecrypted, w, h); ImgDecrypted = logisticDeReplace(imgDecrypted, Key(3), Key(2), Key(1));
end
imgDecrypted = uint8(imgDecrypted);
end
Copy the code
4. Operation results
Matlab version and references
1 matlab version 2014A
2 Reference [1] CAI Limei. MATLAB Image Processing — Theory, Algorithm and Case Analysis [M]. Tsinghua University Press, 2020. [2] Yang Dan, ZHAO Haibin, LONG Zhe. Examples of MATLAB Image Processing In detail [M]. Tsinghua University Press, 2013. [3] Zhou Pin. MATLAB Image Processing and Graphical User Interface Design [M]. Tsinghua University Press, 2013. [4] LIU Chenglong. Proficient in MATLAB Image Processing [M]. Tsinghua University Press, 2015.