# how to confusion image by sin-cos map?

2 views (last 30 days)
Arshub on 10 Dec 2021
Commented: Voss on 10 Dec 2021
I try to implement algorithm in this paper:An efficient color image encryption scheme based on a matrix scrambling method and a new hybrid chaotic map.
This is my cod to implement confusion phase for the algorithm an i write cod for gray image only, please corret it.
in my cod i have two problem, firstly :Error in sc (line 26)
b(j+1)=rem(a(j+1),s);Error using rem :Arguments must be real.
secondly:Pos array have negative no, so should i use abs function to covert all values to positive value ?
close all;
clear all;
clc;
tic
[row,col]=size(timg);
s=row*col;
tencr=reshape(timg,s,1);% 1 means 1 col to make matrix in one dim
x=nan(1,s+1); %<------------PREALLOCATE!!!
y=nan(1,s+1); %<------------PREALLOCATE!!!
Pos=nan(1,s+1); %<------------PREALLOCATE!!!
a=nan(1,s+1);
x(1)=.75;
z=.95;% initial value for cofusion
E=.78;% initial value for cofusion
u=1.58;% initial value for cofusion
D(1) = 0.98; % initial value for diffusion
G(1) = 0.96 ; % % initial value for diffusion
y(1)=u*x(1)*(1-x(1));% initial value
for j=1:s
r=(z/y(j))^(3/2);
x(j+1)=sin(r);
w=E*acos(x(j));
y(j+1)=cos(w);
a(j+1)=x(j+1)*(10^14);
b(j+1)=rem(a(j+1),126000);
Pos(j+1) = round (b(j+1));
%Pos(j+1) = round (rem(a(j+1),s));
disp(Pos);
end
%a=x(1,2:s+1)*(10^14);
%z=uint8( rem(a,256) );
%Pos=rem(a,s);
% Make all values in Pos array positive
%g=abs(Pos);
%disp(g);
%Start of Encryption
encrimg=[];
for m = 1:s
encrimg(m)=tencr(Pos(m));
end
ImageEncr=reshape(encrimg,row,col);% convert matrix to 2D
figure
imshow(ImageEncr)
%Start of Decryption
tdecr=reshape(ImageEncr,s,1);
decrimg=[];
for m = 1:s
decrimg(Pos(m))=tdecr(m);
end
ImageDecr=reshape(decrimg,row,col);
figure
imshow(ImageDecr);

Voss on 10 Dec 2021
At some point in your for j=1:s loop, y(j+1) becomes negative, so in the next iteration r is complex. This is the source of the "Arguments must be real" error. I don't know how you might fix it.
Regarding the negative Pos question, you may consider using mod instead of rem so that a negative argument returns a positive remainder. I don't think doing abs is what you want, but it's hard to say for sure.
##### 2 CommentsShowHide 1 older comment
Voss on 10 Dec 2021
At some point in your for j=1:s loop, y(j+1) becomes negative, so in the next iteration r is complex. This is the source of the "Arguments must be real" error. I don't know how you might fix it.

R2014a

### Community Treasure Hunt

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

Start Hunting!