How to calculate UACI and NPCR between to cipher images whose plain images have only a one-pixel difference?

9 Ansichten (letzte 30 Tage)
I write this code to explain my problem, this cod is simple encrypt algorithm to encrypt image by Xoring image with key
firstly I implement this code to incrypt image then save the cipher image under name 'enc1.bmp:
clc
clear all
tic
load rkey
a=imread('lena_gray.jpg');
[n1 , n2]=size(a);
epk=rkey( 1:n1 ,1:n2 );
enc=bitxor(a,epk);
dec=bitxor(enc,epk);
figure;
imshow(enc);
figure;
imshow(dec);
imwrite(enc,'enc1.jpg');
then i edit one pixel plain image by this step
a=imread('lena_gray.jpg');
a(1,3)=0; %
%the rest of code
.
.
.
imwrite(enc,'enc2.jpg');
and implemet the rest code in step1 once again withe save the encrypted image under name 'enc2.bmp' .
Then i calculate NPCR and UACI between enc1 and enc2 cipher images by add function bellow:
The result are :
NPCR =
0.0468
UACI_value =
5.7267e-04
Why these result with thes value ? it is correct?
NPCR between images very small, this mean that no differents between enc1 and enc2 if i change on pixel only in plain image. But why the value not ideal as 99%. also UACI it is not ideal value.
I implement this code to anather complex encryption algorithm and i change on pixel in pllain image but i diddn't get differences between cipher images. Where is the mistack im my code?
My way for change on pixel in plain image correct?
please tell me what should i do to get ideal value for NPCR and UACI?
% calc NPCR
function [ NPCR ] = Cal_NPCR( imge,enc)
[rows,columns]=size(imge);
step=0;
for i=1:rows
for j=1:columns
if imge(i,j)~= enc(i,j)
step=step+1;
else
step=step+0;
end
end
end
NPCR =(step/(rows*columns))*100;
end
% calc UACI
function [UACI_value] = UACI( after_change,befor_change )
[row, col]=size(befor_change);
AB=[];
for i=1:row
for j=1:col
AB(i,j)=abs(befor_change(i,j)-after_change(i,j));
end
end
UACI_value = sum(AB(:))/(255*row*col)*100
end

Antworten (2)

noor sattar
noor sattar am 21 Feb. 2022
% calc NPCR
function [ NPCR ] = Cal_NPCR( imge,enc)
[rows,columns]=size(imge);
step=0;
for i=1:rows
for j=1:columns
if imge(i,j)~= enc(i,j)
step=step+1;
else
step=step+0;
end
end
end
NPCR =(step/(rows*columns))*100;
end
% calc UACI
function [UACI_value] = UACI( after_change,befor_change )
[row, col]=size(befor_change);
AB=[];
for i=1:row
for j=1:col
AB(i,j)=abs(befor_change(i,j)-after_change(i,j));
end
end
UACI_value = sum(AB(:))/(255*row*col)*100
end

yahia
yahia am 15 Apr. 2023
How to calculate UACI and NPCR for sbox AES

Kategorien

Mehr zu Encryption / Cryptography finden Sie in Help Center und File Exchange

Produkte


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by