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

Private GIT Repository
c79b7ab2faf5c0b70dc8a4bc1e6daf94a7967136
[Cipher_code.git] / Chaotic_code / encryptionprocess2_CBC.m
1 function eimg =encryptionprocess2_CBC(img,h,RK,SubBytes,Pbox,r,IV)\r
2 %%%%%%%%%%%%%% convert image to a vector seq\r
3 %seq=double(reshape(img,1,[]));\r
4 seq_bin=double(byte2bit(uint8(img))) ;\r
5 encr_seq_binary=zeros(1,length(seq_bin));\r
6 %%%%%%%%%%%%%%%%%%%% calculate the number of blocks%%%%%%%%%%%%%%%%%%%%%%%%\r
7 nb= floor(length(seq_bin)/(8*h));\r
8 RKB=byte2bit(RK);\r
9 RKB=RKB(1:r*h*8);\r
10 %RK_bin=double(reshape(byte2bit(RK),r,[]));\r
11 RK_bin=double(reshape(RKB,r,[]));\r
12 Bin_Sbox  =double((Convert_Sbox_Bin(SubBytes)));\r
13 %iv=zeros(1,8*h);\r
14 %iv(end-h+1:end)=IV;\r
15 %IV=iv;\r
16 iv=[];\r
17 for i=1:h\r
18     iv=[iv byte2bit(IV(i))];\r
19 end\r
20 IV=double(iv);\r
21 \r
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
23 %%%%%%%%%%%%%%%%%%%% Applied the confusion process then the bits permutation for r rounds\r
24 for it=1:nb\r
25     temp=seq_bin((it-1)*8*h+1:it*8*h);\r
26     temp=bitxor(temp,IV);\r
27     for itr=1:r\r
28         temp=bitxor(temp,RK_bin(itr,1:h*8));    \r
29         temp= (reshape(Bin_Sbox (double(bit2byte(temp))+1,:)',1,[]));\r
30         temp= temp(Pbox);\r
31     end\r
32     encr_seq_binary((it-1)*8*h+1:it*h*8)=temp;\r
33     IV=temp;\r
34 end\r
35 \r
36 % Convert to Byte representation\r
37 \r
38 %valbin=reshape(valbin,Tb/8,8);\r
39 eimg=(bit2byte(  encr_seq_binary));