필터 지우기
필터 지우기

Image encryption using chaotic map ,, what does this code mean ?

조회 수: 24 (최근 30일)
Samaa Yasser
Samaa Yasser 2021년 4월 25일
편집: Amr Muhammad 2021년 9월 4일
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
Amr Muhammad
Amr Muhammad 2021년 9월 4일
편집: Amr Muhammad 2021년 9월 4일
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
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)

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
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.
  댓글 수: 1
Samaa Yasser
Samaa Yasser 2021년 4월 25일
thanks alot
can i ask you please , so if i want to change the equation to X,Y for example
Xn+1= 1+y(n)n-a*X(n)^2
Yn+1=b*X(n)
how can i re-write the line code [so,in] = sort(x); ??

댓글을 달려면 로그인하십시오.


Image Analyst
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:

카테고리

Help CenterFile Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by