Azzera filtri
Azzera filtri

Image encryption with standard chaotic map

5 visualizzazioni (ultimi 30 giorni)
Asha D.
Asha D. il 29 Mar 2021
Risposto: Milan Bansal il 3 Apr 2024
I have code for chaotic encryption and decryption of image but after decrypting it doesn`t return original image.
Can anyone pls suggest?

Risposte (1)

Milan Bansal
Milan Bansal il 3 Apr 2024
Hi Asha D.
I understand that you are facing an issue with chaotic encryption and decryption of an image where the decrypted image does not return to the original image. The problem appears to be related to discrepancies in how the encryption and decryption processes handle the bit representations of the image data.
Ensure Consistent Bit Depth: The "encrypt" function uses a 9-bit representation "dec2bin(image,9)", which is not standard for image data and likely an error. Image data typically uses 8 bits per color channel. This discrepancy must be corrected to ensure that the decryption process accurately reverses the encryption. Please make the following modifications in the "encrypt" function as shown below to resolve the issue.
clc;clear;
I=imread('Lena.jpg');
% % I=I(1:2:end,1:2:end,1:3); %zoom out
[eI,key]=encrypt(I);
dI=decrypt(eI,key);
figure
subplot(2,2,1);imshow(I);title('origin image');
subplot(2,2,2);imshow(eI);title('encrypted image');
subplot(2,2,3);imshow(dI);title('decrypted image');
function [encrypted,key] = encrypt(image,key)
if nargin==1
key = 10*rand(1,4);
end
x=key(1);y=key(2);k=key(3);h=key(4);
[cols,rows,chans] = size(image);
kk = 2 + exp( mod(h + 10 * sin(k) + k ,2*pi));
hh = 2 + exp( mod(h + 10 * sin(k) ,2*pi));
xx = mod(x + hh * sin(y) + kk * y ,2*pi);
yy = mod(x + hh * sin(y) ,2*pi);
bitArray = dec2bin(image,8); % Modification
bitArray = [bitArray(:)];
N = size(bitArray,1);
posX = zeros(1, 2*N); posY = zeros(1, 2*N);
posX(1)=xx ; posY(1) = yy;
for i = 1 : 2*N-1
posY(i+1) = mod(posX(i) + kk * sin(posY(i)) ,2*pi);
posX(i+1) = mod(posY(i+1) + hh * posX(i) ,2*pi);
end
posX = ceil(posX*N/(2*pi)); posY = ceil(posY*N/(2*pi));
for j = [posX ; posY]
tmp = bitArray(j(1));
bitArray(j(1)) = bitArray(j(2));
bitArray(j(2)) = tmp;
end
bitArray = reshape(bitArray,N/8,8); % Modification
Array = bin2dec(bitArray);
encrypted = uint8(reshape(Array,cols,rows,chans));
end
Please refer to the following documentation links to learn more about "dec2bin" and "bin2dec" functions.
Hope this helps!

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by