+%clear all\r
+%close all\r
+%clc\r
+\r
+\r
+\r
+%%%%%%%%%%%%%%%% Input data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
+[filename, pathname] = uigetfile( {'*.bmp';}, 'Pick a file');\r
+name=[ pathname filename];\r
+data=imread(name);\r
+%data=imresize(data,[64 64])\r
+\r
+h=2;% number of bytes in a block (Tb=h*8)\r
+r=4;% number of rounds\r
+sk=16 % number of byes in a block cipher\r
+strh='SHA-512';\r
+% mode=0==> ECB, \r
+% mode 1==> CBC\r
+\r
+mode=1\r
+\r
+\r
+\r
+% calculate the length of data\r
+SI=size(data);\r
+%len=SI(1)*SI(2)*SI(3);\r
+%lenBits=len*8;\r
+%data_line=reshape(double(data),1,len); \r
+\r
+figure()\r
+imshow(uint8(data));\r
+\r
+%%%%%%%%%%%%%%%%% Key generation%%%%%%%%%%%%%%%%%%%%%%%%\r
+Secretkey=floor(rand(1,sk)*256);\r
+counter=floor(rand(1,sk)*256);\r
+%%%%%%%%%%%%%%%%%%%%%%%%%Creation of cipher layer's%%%%%%%%%%%%%%%%%%%%\r
+[RK,Sbox,Pbox]=Dynamickeygenerationnew(Secretkey,counter,strh,h);\r
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Change in data block%%%%%%%%%%%%%%%%%%%%%%%% \r
+\r
+\r
+\r
+\r
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Encryption Process%%%%%%%%%%%%%%%%%%%%%\r
+tic\r
+if mode==0\r
+eimg =encryptionprocess2(data,h,RK,Sbox,Pbox,r);\r
+elseif mode==1\r
+IV=double(floor(rand(1,h)*256)); \r
+eimg =encryptionprocess2_CBC(data,h,RK,Sbox,Pbox,r,IV); \r
+end\r
+\r
+toc\r
+eimg2=reshape(eimg,size(data));\r
+\r
+figure()\r
+imshow(uint8(eimg2));\r
+\r
+%%%%%%%%%%%%%%%%%%%%% Decryption Side%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
+%%%%%%%%%%%%%%%%%%%% calculate the inverse substitution and diffusion\r
+%%%%%%%%%%%%%%%%%%%% layer%%%%%%%%%%%%%%%%\r
+ Inv_Sbox= inverse_tables(Sbox);\r
+ Inv_Pbox= inverse_tables2(Pbox);\r
+ \r
+ \r
+ if mode==0\r
+ dimg =decryptionprocess2(eimg,h,RK,Inv_Sbox,Inv_Pbox,r);\r
+elseif mode==1\r
+\r
+ dimg =decryptionprocess2_CBC(eimg,h,RK,Inv_Sbox,Inv_Pbox,r,IV); \r
+ end\r
+\r
+% tic\r
+% dimg =decryptionprocess2(eimg,h,RK,Inv_Sbox,Inv_Pbox,r);\r
+% toc\r
+ dimg=reshape(dimg,size(data));\r
+ figure()\r
+ imshow(uint8(dimg));\r
+ \r