NPCR and UACI test

Encrypted File 1:
Encrypted File 2:

NPCR (Number of Pixels Change Rate)

NPCR assesses how sensitively an encryption algorithm responds to a small change in the input image. It's defined as the percentage of different pixels between two encrypted images that were generated from two nearly identical source images (usually differing by just one pixel).
The formula for calculating NPCR is:
N P C R = ( i = 1 M j = 1 N D ( i , j ) M × N ) × 100 % N P C R = i = 1 M j = 1 N D ( i , j ) M × N × 100 % NPCR=((sum_(i=1)^(M)sum_(j=1)^(N)D(i,j))/(M xx N))xx100%NPCR = \left( \frac{\sum_{i=1}^{M} \sum_{j=1}^{N} D(i,j)}{M \times N} \right) \times 100\%NPCR=(i=1Mj=1ND(i,j)M×N)×100%
where:
  • M M MMM and N N NNN are the dimensions of the images (height and width, respectively).
  • D ( i , j ) D ( i , j ) D(i,j)D(i,j)D(i,j) is a binary function that compares the pixel at position ( i , j ) ( i , j ) (i,j)(i,j)(i,j) in the two encrypted images. It is defined as:
D ( i , j ) = { 1 , if E 1 ( i , j ) E 2 ( i , j ) 0 , if E 1 ( i , j ) = E 2 ( i , j ) D ( i , j ) = 1 ,      if  E 1 ( i , j ) E 2 ( i , j ) 0 ,      if  E 1 ( i , j ) = E 2 ( i , j ) D(i,j)={[1",","if "E_(1)(i","j)!=E_(2)(i","j)],[0",","if "E_(1)(i","j)=E_(2)(i","j)]:} D(i,j) = \begin{cases} 1, & \text{if } E_1(i,j) \neq E_2(i,j) \\ 0, & \text{if } E_1(i,j) = E_2(i,j) \end{cases} D(i,j)={1,if E1(i,j)E2(i,j)0,if E1(i,j)=E2(i,j)
  • E 1 ( i , j ) E 1 ( i , j ) E_(1)(i,j)E_1(i,j)E1(i,j) and E 2 ( i , j ) E 2 ( i , j ) E_(2)(i,j)E_2(i,j)E2(i,j) are the pixel values at position ( i , j ) ( i , j ) (i,j)(i,j)(i,j) in the first and second encrypted images, respectively.

UACI (Unified Average Changing Intensity)

UACI measures the average intensity difference between two encrypted images, providing insight into how much the encryption algorithm alters pixel values on average.
The formula for UACI is:
U A C I = ( 1 M × N i = 1 M j = 1 N | E 1 ( i , j ) E 2 ( i , j ) | 255 ) × 100 % U A C I = 1 M × N i = 1 M j = 1 N E 1 ( i , j ) E 2 ( i , j ) 255 × 100 % UACI=((1)/(M xx N)sum_(i=1)^(M)sum_(j=1)^(N)(|E_(1)(i,j)-E_(2)(i,j)|)/(255))xx100%UACI = \left( \frac{1}{M \times N} \sum_{i=1}^{M} \sum_{j=1}^{N} \frac{\left| E_1(i,j) - E_2(i,j) \right|}{255} \right) \times 100\%UACI=(1M×Ni=1Mj=1N|E1(i,j)E2(i,j)|255)×100%
where:
  • M M MMM and N N NNN are the dimensions of the images.
  • E 1 ( i , j ) E 1 ( i , j ) E_(1)(i,j)E_1(i,j)E1(i,j) and E 2 ( i , j ) E 2 ( i , j ) E_(2)(i,j)E_2(i,j)E2(i,j) represent the pixel values at position ( i , j ) ( i , j ) (i,j)(i,j)(i,j) in the first and second encrypted images, respectively.
  • The absolute difference between the pixel values E 1 ( i , j ) E 1 ( i , j ) E_(1)(i,j)E_1(i,j)E1(i,j) and E 2 ( i , j ) E 2 ( i , j ) E_(2)(i,j)E_2(i,j)E2(i,j) is divided by 255, assuming an 8-bit per pixel image format where pixel values range from 0 to 255.
These formulas for NPCR and UACI are integral for evaluating the effectiveness and security of image encryption algorithms, ensuring they are sufficiently sensitive to changes in the input image and significantly alter the image's pixel values to thwart potential attacks.