]> AND Private Git Repository - Cipher_code.git/blob - Chaotic_code/main2.m
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
adding of the chaotic cipher code
[Cipher_code.git] / Chaotic_code / main2.m
1 %clear all\r
2 %close all\r
3 %clc\r
4 \r
5 \r
6 \r
7 %%%%%%%%%%%%%%%% Input data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
8 [filename, pathname] = uigetfile( {'*.bmp';}, 'Pick a file');\r
9 name=[ pathname filename];\r
10 data=imread(name);\r
11 %data=imresize(data,[64 64])\r
12 \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
16 strh='SHA-512';\r
17 %  mode=0==> ECB, \r
18 %  mode 1==> CBC\r
19 \r
20 mode=1\r
21 \r
22 \r
23 \r
24 % calculate the length of data\r
25 SI=size(data);\r
26 %len=SI(1)*SI(2)*SI(3);\r
27 %lenBits=len*8;\r
28 %data_line=reshape(double(data),1,len); \r
29 \r
30 figure()\r
31 imshow(uint8(data));\r
32 \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
39 \r
40 \r
41 \r
42 \r
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Encryption Process%%%%%%%%%%%%%%%%%%%%%\r
44 tic\r
45 if mode==0\r
46 eimg =encryptionprocess2(data,h,RK,Sbox,Pbox,r);\r
47 elseif mode==1\r
48 IV=double(floor(rand(1,h)*256));  \r
49 eimg =encryptionprocess2_CBC(data,h,RK,Sbox,Pbox,r,IV);       \r
50 end\r
51 \r
52 toc\r
53 eimg2=reshape(eimg,size(data));\r
54 \r
55 figure()\r
56 imshow(uint8(eimg2));\r
57 \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
64  \r
65  \r
66  if mode==0\r
67  dimg =decryptionprocess2(eimg,h,RK,Inv_Sbox,Inv_Pbox,r);\r
68 elseif mode==1\r
69 \r
70  dimg =decryptionprocess2_CBC(eimg,h,RK,Inv_Sbox,Inv_Pbox,r,IV);      \r
71  end\r
72 \r
73 %  tic\r
74 %  dimg =decryptionprocess2(eimg,h,RK,Inv_Sbox,Inv_Pbox,r);\r
75 %  toc\r
76  dimg=reshape(dimg,size(data));\r
77  figure()\r
78  imshow(uint8(dimg));\r
79  \r