I. 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

Two, some source code

Painted % function function - painted image encryption and decryption processing total interface % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the clear all; button_color=[0.529 0.808 0.922]; % create window h=figure('Color'[0 0.4 0].'MenuBar'.'none'.'name'.'Image encryption Software'.'NumberTitle'.'off'.'Position'[420 150 600 500]);
%'MenuBar'Figure indicates display control menu. None indicates hide %'NumberTitle'The value of the'off'No window in the title bar of the serial number on that % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % interface background defaults h_b = axes ('units'.'normalized'.'position'[0 0 1 1]);  
uistack(h_b,'down')  
Q_bg=imread('bg.jpg');  
image(Q_bg);  
colormap gray  
set(h_b,'handlevisibility'.'off'.'visible'.'off'); % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- f1 = % % level menu menu uimenu (h,'Label'.'&' File File ');
f2=uimenu(h,'Label'.'& Edit Edit');
f3=uimenu(h,'Label'.'Image processing');
f4=uimenu(h,'Label'.'Image encryption');
f5=uimenu(h,'Label'.'& help help'); % m11=uimenu(f1,'Label'.'open'.'Accelerator'.'O'.'Callback'.'picture_open');
m12=uimenu(f1,'Label'.'save'.'Accelerator'.'S'.'Callback'.'picture_save');
m13=uimenu(f1,'Label'.'Image Format Conversion');
m14=uimenu(f1,'Label'.'Close all Windows'.'Callback'.'close all; ');
m15=uimenu(f1,'Label'.'exit'.'Accelerator'.'Q'.'Callback'.'exit'.'Separator'.'On');

% m21=uimenu(f2,'Label'.'Change button color'.'Callback'.'button_color=uisetcolor');
m22=uimenu(f2,'Label'.'Background change'.'Callback'.'bg_select; ');
m23=uimenu(f2,'Label'.'Image cropping'.'Callback'.'imshow(Q_show); Q_imcrop=imcrop; Q_global=Q_imcrop; imshow(Q_imcrop); ');

m31=uimenu(f3,'label'.'Image rotation'.'Callback'.'picture_rotate; ');
m32=uimenu(f3,'label'.'Image ashing'.'Callback'.'picture_rgbtogray; ');
m33=uimenu(f3,'label'.'Image binarization'.'Callback'.'picture_graytotwo; ');
m34=uimenu(f3,'label'.'Image Mosaic'.'Callback'.'picture_mosaic; ');

m41=uimenu(f4,'label'.'Arnold_jms'.'Callback'.'bu_trigger1; ');
m42=uimenu(f4,'label'.'Arnold_chaos'.'Callback'.'bu_trigger2; '); Painted % function function - Arnold_jms encryption/decryption painted interface % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- button_color = [0.8 0.68 0.604]; % create window h1=figure('Color',button_color,'MenuBar'.'none'.'name'.'★Arnold_jms encryption/decryption ★'.'NumberTitle'.'off'.'Position'[220 150 600 500]);
%'MenuBar'Figure indicates display control menu. None indicates hide %'NumberTitle'The value of the'off'No window serial number on in the title bar means AXES ('Position'[. 0 3. 6. 6.]); Q_open=Q_global; imshow(Q_open); title('Image to be processed'); % % for processing images displayed in the window -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % interface background defaults h_b = axes ('units'.'normalized'.'position'[0 0 1 1]);  
uistack(h_b,'down')  
Q_bg=imread('bg1.jpg');  
image(Q_bg);  
colormap gray  
set(h_b,'handlevisibility'.'off'.'visible'.'off'); % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % key input window EditBox = uicontrol (h1,'Style'.'edit'.'Position'[475 320 50 20],...
   'Callback'. ['NumStr=get(EditBox,''String''); '.'Num=str2num(NumStr); ']); Textpos=uicontrol(h1,'Style'.'text'.'Position'. [400 320 60 20].'FontSize'.12.'String'.'key r'.'BackgroundColor'[1 0.894 0.710].'FontSize'.13); % button=uicontrol(h1,'Style'.'pushbutton'.'String'.'Save image'.'Position'. [425 150 100 40].'BackgroundColor',button_color,...
    'Callback'.'picture_save; ');

button_bg=uicontrol(h1,'Style'.'pushbutton'.'String'.'Background change'.'Position'. [425 225 100 40].'BackgroundColor',button_color,...
    'Callback'.'bg_select; '); % Q: encrypted image %alignment: encrypted sequence % M: input key % A, B, C: image 3D % encrypted k=0; Decryption k =1; The % u take3.5699456to4The number between %lq100Function Q_global=chaos(Image,k,u,lq,mm)if u>4 || u<3.5699456
   msgbox('u must be a number between 3.5699456 and 4! '.'Error warning'.'warn');
   return;
end
if lq<100
   msgbox('Lq must be greater than 100! '.'Error warning'.'warn');
   return;
end
if mm>1 || mm<0
   msgbox('mm must be greater than 0 and less than 1! '.'Error warning'.'warn');
   return;
end



if length(size(Image))= =2% grayscale imageif k==0% encryption SSQ = lq; % Chaotic sequence xs=u after SSQ bit; Q=Image; [a,b]=size(Q); N=a*b; alignment=zeros(1,N);
alignment(1)=mm;

for yu=1:ssq
    alignment(1)=xs*alignment(1)-xs*alignment(1) ^2;
end
for k=1:N- 1
    alignment(k+1)=xs*alignment(k)-xs*alignment(k)^2;
end
alignment=mod(10^13*alignment,256);
alignment=uint8(alignment);
n=1;
for ii=1:a
    for jj=1:b
        Q(ii,jj)=bitxor(alignment(n),Q(ii,jj));
        n=n+1;
    end
end
Qtwochaos_jm=Q;
Q_global=Qtwochaos_jm;
imshow(Qtwochaos_jm);
title('Encrypted image');
msgbox('Encryption successful! '.'tip'.'warn'); % to decryptelsessq=lq; % Chaotic sequence xs=u after SSQ bit; Qcrypt=Image; [aa,bb]=size(Qcrypt); NN=aa*bb; alignment=zeros(1,NN);
alignment(1)=mm;
for yu=1:ssq
    alignment(1)=xs*alignment(1)-xs*alignment(1) ^2;
end
for k=1:NN- 1
    alignment(k+1)=xs*alignment(k)-xs*alignment(k)^2;
end
alignment=mod(10^13*alignment,256);
alignment=uint8(alignment);
nn=1;
for ii=1:aa
    for jj=1:bb
        Qcrypt(ii,jj)=bitxor(alignment(nn),Qcrypt(ii,jj));
        nn=nn+1;
    end
end
Qtwochaos_de=Qcrypt;
Q_global=Qtwochaos_de;
imshow(Qtwochaos_de);
title('Decrypted image');
msgbox('Decryption succeeded! '.'tip'.'warn');
end  

    
else   %rgb 
if k==0% encryption SSQ = lq; % Chaotic sequence xs=u after SSQ bit; Q=Image; [a,b,~]=size(Q); N=a*b; alignment=zeros(1,N);
alignment(1)=mm;

for yu=1:ssq
    alignment(1)=xs*alignment(1)-xs*alignment(1) ^2;
end
for k=1:N- 1
    alignment(k+1)=xs*alignment(k)-xs*alignment(k)^2;
end
alignment=mod(10^13*alignment,256);
alignment=uint8(alignment);
n=1;
for ii=1:a
    for jj=1:b
        Q(ii,jj,1)=bitxor(alignment(n),Q(ii,jj,1));
        Q(ii,jj,2)=bitxor(alignment(n),Q(ii,jj,2));
        Q(ii,jj,3)=bitxor(alignment(n),Q(ii,jj,3));
        n=n+1;
    end
end
Qrgbchaos_jm=Q;
Q_global=Qrgbchaos_jm;
imshow(Qrgbchaos_jm);
title('Encrypted image');
msgbox('Encryption successful! '.'tip'.'warn'); % to decryptelsessq=lq; % Chaotic sequence xs=u after SSQ bit; Qcrypt=Image; [aa,bb,~]=size(Qcrypt); NN=aa*bb; alignment=zeros(1,NN);
alignment(1)=mm;
for yu=1:ssq
    alignment(1)=xs*alignment(1)-xs*alignment(1) ^2;
end
for k=1:NN- 1
    alignment(k+1)=xs*alignment(k)-xs*alignment(k)^2;
end
alignment=mod(10^13*alignment,256);
alignment=uint8(alignment);
nn=1;
for ii=1:aa
    for jj=1:bb
        Qcrypt(ii,jj,1)=bitxor(alignment(nn),Qcrypt(ii,jj,1));
        Qcrypt(ii,jj,2)=bitxor(alignment(nn),Qcrypt(ii,jj,2));
        Qcrypt(ii,jj,3)=bitxor(alignment(nn),Qcrypt(ii,jj,3));
        nn=nn+1;
    end
end
Qrgbchaos_de=Qcrypt;
Q_global=Qrgbchaos_de;
imshow(Qrgbchaos_de);
title('Decrypted image');
msgbox('Decryption succeeded! '.'tip'.'warn');
end

end
%--------------------------------------------------------------------





Copy the code

3. 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.