'How to encrypt image with nine-dimensional chaos using MATLAB?
In this code, I want to encrypt the image using a nine-dimensional chaos system. so in the beginning we enter the image with dimensions [M N]= 512x512x3 where M is row and M is col. Here is the code:
I1=imread('Aletta.(Isekai.Shokudou).600.2121109.jpg');
I=imresize(I1,[512 512]);
[M,N]=size(I);
rounds=2;
% To Make Sure That image size is even
if mod(M,2)==1
I(M+1,:)=uint8(0);
M=M+1;
end
if mod(N,2)==1
I(:,N+1)=uint8(0);
N=N+1;
end
MN=M*N;
for round_iter=1:rounds
% #2
P=double(I(:));%convert image I to vector P
% #3
x=(sum(P)+MN)/(MN+(2^23));% to clculate initial key
for i=2:9
x(i)=mod(x(i-1)*1e6,1);
end
a=0.5;b1=10/3;b2=3/5;b3=6/5;b4=1/5;b5=4/3;b6=8/3;r=24.00;
L=@(t,x) [-a.*b1.*x(1)-x(2).*x(4)+b4.*x(4)^2+b3.*x(3).*x(5)-a.*b2.*x(7);
-a.*x(2)+x(1).*x(4)-x(2).*x(5)+x(4).*x(5)-(a.*x(9))/2;
-a.*b1.*x(3)+x(2).*x(4)-b4.*x(2)^2-b3.*x(1).*x(5)+a.*b2.*x(8);
-a.*x(4)-x(2).*x(3)-x(2).*x(5)+x(4).*x(5)+(a.*x(9))/2;
-a.*b5.*x(5)+(x(2)^2/2)-(x(4)^2/2);
-b6.*x(6)+x(2).*x(9)-x(4).*x(9);
-b1.*x(7)-r.*x(1)+ 2.*x(5).*x(8)-x(4).*x(9);
-b1.*x(8)+r.*x(3)-2.*x(5).*x(7)+x(2).*x(9);
-x(9)-r.*x(2)+r.*x(4)-2.*x(2).*x(6)+2.*x(4).*x(6)+x(4).*x(7)-x(2).*x(8)];
N0=.9865*MN/3;
MN3=ceil(MN/3);
[T,Y]=ode45(L,[N0 MN3],x);
% #4
L=Y(1:MN3,1:2:5);
L=L(:);L=L(1:MN);
When we run this code, the result showed this error in the encryption part:
Index in position 1 exceeds array bounds. Index must not exceed 73097.
Error in Encrypt
L=Y(1:MN3,1:2:5);
How could I solve this please?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
