7 %%%%%%%%%%%%%%%% Input data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
8 [filename, pathname] = uigetfile( {'*.bmp';}, 'Pick a file');
\r
9 name=[ pathname filename];
\r
11 %data=imresize(data,[64 64])
\r
13 h=2;% number of bytes in a block (Tb=h*8)
\r
14 r=4;% number of rounds
\r
15 sk=16 % number of byes in a block cipher
\r
24 % calculate the length of data
\r
26 %len=SI(1)*SI(2)*SI(3);
\r
28 %data_line=reshape(double(data),1,len);
\r
31 imshow(uint8(data));
\r
33 %%%%%%%%%%%%%%%%% Key generation%%%%%%%%%%%%%%%%%%%%%%%%
\r
34 Secretkey=floor(rand(1,sk)*256);
\r
35 counter=floor(rand(1,sk)*256);
\r
36 %%%%%%%%%%%%%%%%%%%%%%%%%Creation of cipher layer's%%%%%%%%%%%%%%%%%%%%
\r
37 [RK,Sbox,Pbox]=Dynamickeygenerationnew(Secretkey,counter,strh,h);
\r
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Change in data block%%%%%%%%%%%%%%%%%%%%%%%%
\r
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Encryption Process%%%%%%%%%%%%%%%%%%%%%
\r
46 eimg =encryptionprocess2(data,h,RK,Sbox,Pbox,r);
\r
48 IV=double(floor(rand(1,h)*256));
\r
49 eimg =encryptionprocess2_CBC(data,h,RK,Sbox,Pbox,r,IV);
\r
53 eimg2=reshape(eimg,size(data));
\r
56 imshow(uint8(eimg2));
\r
58 %%%%%%%%%%%%%%%%%%%%% Decryption Side%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
60 %%%%%%%%%%%%%%%%%%%% calculate the inverse substitution and diffusion
\r
61 %%%%%%%%%%%%%%%%%%%% layer%%%%%%%%%%%%%%%%
\r
62 Inv_Sbox= inverse_tables(Sbox);
\r
63 Inv_Pbox= inverse_tables2(Pbox);
\r
67 dimg =decryptionprocess2(eimg,h,RK,Inv_Sbox,Inv_Pbox,r);
\r
70 dimg =decryptionprocess2_CBC(eimg,h,RK,Inv_Sbox,Inv_Pbox,r,IV);
\r
74 % dimg =decryptionprocess2(eimg,h,RK,Inv_Sbox,Inv_Pbox,r);
\r
76 dimg=reshape(dimg,size(data));
\r
78 imshow(uint8(dimg));
\r