How to calculate UACI and NPCR between to cipher images whose plain images have only a one-pixel difference?
    10 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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
0 comentarios
Respuestas (2)
  noor sattar
 el 21 de Feb. de 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
0 comentarios
Ver también
Categorías
				Más información sobre Encryption / Cryptography en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


