Error using bitxor Inputs must have the same size.
Show older comments
Hello there,
i have a proplem with bitxor function :
Error using bitxor Inputs must have the same size.
the first input " original " & the second input " cipher " has the following sizes like below :

How can i make original & cipher variable of same size ?
and here is my code :
%Using Logistic chaotic mapping, sequence encryption of grayscale images
original = imread('pp.jpg');
figure(1);
subplot(1,3,1);
imshow(original);
title('original');
[M,N]=size(original);
x=0.1;
u=4;
% %Iterative200Second, achieve full chaotic state
for i=1:200
x=u*x*(1-x);
end
% %Generate a single-dimensional chaotic encryption sequence
A=zeros(1,M*N); %generate1*Mn zero matrix
A(1)=x;
%Generate chaotic sequence
for i=1:M*N-1
A(i+1)=u*A(i)*(1-A(i));
end
%Normalized sequence
B=uint8(255*A); %Convert to 255 type of data
% %Transforming into two-dimensional chaotic encryption sequence
Cipher=reshape(B,M,N); %Reshape changes the shape of the specified matrix, but the number of elements does not change; here B is converted to M line, N columns
Encrypted =bitxor(original ,Cipher); %Tone or operation encryption
figure(1);
subplot(1,3,2);
imshow(Encrypted);
title('Encrypted');
%Decryption
Decrypted=bitxor(Encrypted,Cipher); %Different or operation decryption
figure(1);
subplot(1,3,3);
imshow(Decrypted);
title('Decrypted');
%Draw a histogram of original Image and Encrypted Image
figure(2);
subplot(1,3,1);
imhist(original);
title(' original ');
figure(2);
subplot(1,3,2);
imhist(Encrypted);
title('Encrypted');
figure(2);
subplot(1,3,3);
imhist(Decrypted);
title('Decrypted');
Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Encryption / Cryptography in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!