Image encryption using chaotic map ,, what does this code mean ?
23 views (last 30 days)
Show older comments
please this code is apart from a code which used to encrypt an image using logistic map key
i just want to know what does this line " [so , in ] = sort (x)" mean ??
and also i want explaination of the confusion step ,, please i need a help ,
tic
timg = img;
r = 3.62;
x(1) = 0.7;
row = size(img,1);
col = size(img,2);
s = row*col;
for n=1:s-1
x(n+1) = r*x(n)*(1-x(n));
end
[so,in] = sort(x);
%Start of Confusion
timg = timg(:);
for m = 1:size(timg,1)
t1 = timg(m);
timg(m)=timg(in(m));
timg(in(m))=t1;
end
2 Comments
Amr Muhammad
on 4 Sep 2021
Edited: Amr Muhammad
on 4 Sep 2021
Sort here means that:
you will generate a vector "In". The image vector will be confused and reconfused according to the values of "In" array.
For example:
Img=[4,2,5,6,9]
In=[3,5,1,4,2]
Imgencr=[Img(In(1) , Img(In(2) , Img(In(3) , Img(In(4) ,Img(In(5) ]
=[5, 9, 4, 6, 2 ]
Imgdecr[In(1)] = Imgencr[1] -> Imgdecr[3] = 5
Imgdecr[In(2)] = Imgencr[2] -> Imgdecr[5] = 9
Imgdecr[In(3)] = Imgencr[3] -> Imgdecr[1] = 4
Imgdecr[In(4)] = Imgencr[4] -> Imgdecr[4] = 6
Imgdecr[In(5)] = Imgencr[5] -> Imgdecr[2] = 2
Imgdecr=[ Imgdecr[1] , Imgdecr[2] , Imgdecr[3] , Imgdecr[4] , Imgdecr[5] ]
=[ 5, 9, 4, 6, 2 ]
is the same the original one (=img)
Amr Muhammad
on 4 Sep 2021
Edited: Amr Muhammad
on 4 Sep 2021
The complete program used to confuse and reconfuse an image:
close all;
clear all;
clc;
tic
img = imread('cameraman.jpg');
timg=rgb2gray(img);
r = 3.62;
x(1) = 0.7;
row = size(timg,1);
col = size(timg,2);
s = row*col;
for n=1:s-1
x(n+1) = r*x(n)*(1-x(n));
end
[so,in] = sort(x);
tencr=reshape(timg,s,1);
%Start of Encryption
encrimg=[];
for m = 1:s
encrimg(m)=tencr(in(m));
end
ImageEncr=reshape(encrimg,row,col);
figure
imshow(ImageEncr/255)
%Start of Decryption
tdecr=reshape(ImageEncr,s,1);
decrimg=[];
for m = 1:s
decrimg(in(m))=tdecr(m);
end
ImageDecr=reshape(decrimg,row,col);
figure
imshow(ImageDecr/255)
Answers (2)
Walter Roberson
on 25 Apr 2021
[so,in] = sort(x);
means that the vector x is to be sorted in ascending order, and that the sorted values are to be stored in the variable named "so". Furthermore, the variable named "in" is to be assigned indices. in(1) is to be assigned the index in x that so(1) came from, in(2) is where so(2) came from. The output is such that x(in)==so.
We cannot explain encryption algorithms here for legal reasons.
Image Analyst
on 25 Apr 2021
It means that the author never learned professional code writing techniques. Techniques like using descriptive variable names and putting in comments. If he had, you would have seen something like
% Sort x in ascending order and return the sorted x values and
% the original location of the values in the unsorted, original vector.
[sortedValues, sortOrder] = sort(x, 'ascend');
and you probably would not have had to ask your question. Don't be like that bad programmer. Read these:
0 Comments
See Also
Categories
Find more on Encryption / Cryptography in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!