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!