Image encryption using chaotic map ,, what does this code mean ?
6 次查看(过去 30 天)
显示 更早的评论
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
3 个评论
Amr Muhammad
2021-9-4
编辑:Amr Muhammad
2021-9-4
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)
sajjad
2024-12-15
Its very nice code. I am als working on cryptography (Image Encryption and Decryption).
回答(2 个)
Walter Roberson
2021-4-25
[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
2021-4-25
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Encryption / Cryptography 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!