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

Private GIT Repository
new
[Cipher_code.git] / Chaotic_code / decryptionprocess2_CBC.m
1 function dimg =decryptionprocess2_CBC(img,h,RK,Inv_SubBytes,Inv_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 decr_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 %RK_bin=double(reshape(byte2bit(RK),r,[]));\r
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
14 %%%%%%%%%%% Convert S-box to binary representation to avoid repeat the\r
15 %%%%%%%%%%% byte2bit conversion\r
16 Bin_Sbox  =double(Convert_Sbox_Bin(Inv_SubBytes));\r
17 \r
18 iv=[];\r
19 for i=1:h\r
20     iv=[iv byte2bit(IV(i))];\r
21 end\r
22 IV=double(iv);\r
23 \r
24 \r
25 %%%%%%%%%%%%%%%%%%%% Applied the confusion process (r rounds)\r
26 for it=1:nb\r
27      temp=seq_bin((it-1)*8*h+1:it*h*8);\r
28      temp_IV=temp;\r
29     for itr=r:-1:1       \r
30         temp= temp(Inv_Pbox);\r
31         temp=reshape(Bin_Sbox (double(bit2byte(temp))+1,:)',1,[]);\r
32         temp=bitxor(temp,RK_bin(itr,1:h*8));   \r
33     end\r
34     temp=bitxor(temp,IV);\r
35     decr_seq_binary((it-1)*8*h+1:it*h*8)=temp;\r
36     IV= temp_IV;\r
37 end\r
38 \r
39 % Convert to Byte representation\r
40 \r
41 %valbin=reshape(valbin,Tb/8,8);\r
42 dimg=uint8(bit2byte(decr_seq_binary));