Help me understand this code please

I do understand the first step so dont explain it. Just need to understand 2nd step line by line where a diffusion key is created using logistic map.
First Step:
r = 3.62;
x(1) = 0.7;
row = size(img,1);
col = size(img,2);
s = row*col;
%Creation of Logistic function
for n=1:s-1
x(n+1) = r*x(n)*(1-x(n));
end
2nd Step:
%Creation of diffusion key
p=3.628;
k(1)=0.632;
for n=1:s-1
k(n+1) = cos(p*acos(k(n)));
end
k = abs(round(k*255));
ktemp = de2bi(k);
ktemp = circshift(ktemp,1);
ktemp = bi2de(ktemp)';
key = bitxor(k,ktemp);
%Ending creation of diffusion key

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 13 Jul 2019
Edited: KALYAN ACHARJYA on 13 Jul 2019
First Step:
r = 3.62; % Define r
x(1) = 0.7; %define array index 1=0.7
row = size(img,1); %Finding row size of img
col = size(img,2); %Finding colm size of img
s = row*col; %s=row*colm
%Creation of Logistic function
for n=1:s-1 % Loop n=1 to s-1
x(n+1) = r*x(n)*(1-x(n)); % First x(2), x(1 is already defined), to find x array
end
2nd Step:
p=3.628; % Define p
k(1)=0.632; %define array k index 1
for n=1:s-1 % Loop n=1 to s-1
k(n+1) = cos(p*acos(k(n))); % First k(2), k(1 is already defined), to find k array
end
k = abs(round(k*255)); % Multiple k with 255, then roundoff, and consider absolute
ktemp = de2bi(k); % decimal to binary k to Ktemp
ktemp = circshift(ktemp,1); % One bit circular shift of K temp
ktemp = bi2de(ktemp)'; % Binary to decimal , replace k temp
key = bitxor(k,ktemp); %key= xor opeartion between k and ktemp
The application, ask the coder who done the code.

2 Comments

Thanks alot.
for n=1:s-1
k(n+1) = cos(p*acos(k(n)));
end
I want to know what is actually happening in this for loop.
Secondly why are they doing this.. decimal to binary then binary to decimal again.
k = abs(round(k*255));
ktemp = de2bi(k);
ktemp = circshift(ktemp,1);
ktemp = bi2de(ktemp)';
It is simply 1 bit circle shift of element to add confusion in the generated array.

Sign in to comment.

Categories

Asked:

on 13 Jul 2019

Edited:

on 13 Jun 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!