function dimg =decryptionprocess(img,h,RK,Inv_SubBytes,Inv_Pbox,r)
%%%%%%%%%%%%%% convert image to a vector seq
%seq=double(reshape(img,1,[]));
seq_bin=double(byte2bit(uint8(img))) ;
decr_seq_binary=zeros(1,length(seq_bin));
%%%%%%%%%%%%%%%%%%%% calculate the number of blocks%%%%%%%%%%%%%%%%%%%%%%%%
nb= floor(length(seq_bin)/(8*h));
RK_bin=double(reshape(byte2bit(RK),r,[]));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Convert S-box to binary representation to avoid repeat the
%%%%%%%%%%% byte2bit conversion
Bin_Sbox  =double(Convert_Sbox_Bin(Inv_SubBytes));
%%%%%%%%%%%%%%%%%%%% Applied the confusion process (r rounds)
for it=1:nb
     temp=seq_bin((it-1)*8*h+1:it*h*8);
    for itr=r:-1:1       
        temp= temp(Inv_Pbox);
        temp=reshape(Bin_Sbox (double(bit2byte(temp))+1,:)',1,[]);
       % double(byte2bit(Inv_SubBytes(double(bit2byte(temp))+1)));
        %
%         size(temp)
        %byte2bit(Inv_SubBytes(double(bit2byte(temp))+1));
        %temp= Inv_SubBytes(temp+1);
        temp=bitxor(temp,RK_bin(itr,1:h*8));   
    end
    decr_seq_binary((it-1)*8*h+1:it*h*8)=temp;
end

% Convert to Byte representation

%valbin=reshape(valbin,Tb/8,8);
dimg=uint8(bit2byte(decr_seq_binary));