├── Baboon.tif ├── Barbara.png ├── Peppers.tif ├── Plane.tif ├── lena_512.tif ├── Cameraman_512.tif ├── DNA_Encryption.mat ├── DNA_Dencryption.mat ├── entropy.m ├── start_point_calcalutor.m ├── Image_Permutation.m ├── Image_Diffusion.m ├── NPCR_UACI.m ├── Bit_Reversion.m ├── AdjancyCorrPixelRand.m ├── var_chi.m ├── rule_2.m ├── rule_3.m ├── rule_4.m ├── rule_5.m ├── rule_7.m ├── rule_6.m ├── rule_8.m ├── rule_1.m ├── README.md ├── DNA_Convert.m └── main.m /Baboon.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uerkan80/Image-Encryption/HEAD/Baboon.tif -------------------------------------------------------------------------------- /Barbara.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uerkan80/Image-Encryption/HEAD/Barbara.png -------------------------------------------------------------------------------- /Peppers.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uerkan80/Image-Encryption/HEAD/Peppers.tif -------------------------------------------------------------------------------- /Plane.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uerkan80/Image-Encryption/HEAD/Plane.tif -------------------------------------------------------------------------------- /lena_512.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uerkan80/Image-Encryption/HEAD/lena_512.tif -------------------------------------------------------------------------------- /Cameraman_512.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uerkan80/Image-Encryption/HEAD/Cameraman_512.tif -------------------------------------------------------------------------------- /DNA_Encryption.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uerkan80/Image-Encryption/HEAD/DNA_Encryption.mat -------------------------------------------------------------------------------- /DNA_Dencryption.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uerkan80/Image-Encryption/HEAD/DNA_Dencryption.mat -------------------------------------------------------------------------------- /entropy.m: -------------------------------------------------------------------------------- 1 | function [ h ] = entropy( x, n ) 2 | error( nargchk(1,2,nargin)); 3 | if nargin < 2 4 | n = 256; 5 | end 6 | x = double(x); 7 | xh = hist( x(:), n); 8 | xh = xh / sum(xh(:)); 9 | i = find(xh); 10 | h = - sum(xh(i).*log2(xh(i))); 11 | end -------------------------------------------------------------------------------- /start_point_calcalutor.m: -------------------------------------------------------------------------------- 1 | function [X,U]=start_point_calcalutor(public_key,secret_key) 2 | 3 | E=mod(public_key+secret_key,2); % Main Key 4 | E=reshape(E,8,8,8); 5 | F=mod(sum(E,2),2); 6 | F=reshape(F,8,8); 7 | G=[128 64 32 16 8 4 2 1]*F; 8 | X=G(1:4)/256; % The initial values 9 | U=G(5:8)/256+mod(G(5:8),10); % The control Parameters 10 | end -------------------------------------------------------------------------------- /Image_Permutation.m: -------------------------------------------------------------------------------- 1 | function [image_per] = Image_Permutation(image,m,n,x1,u1,Type) 2 | x(1) = x1; 3 | for i = 2:(m*n) 4 | x(i)=mod(((exp(1)+u1))*log(x(i-1)),1); 5 | end 6 | [~,Pos]=sort(x); 7 | Pos=Pos'; 8 | switch Type 9 | case 'Encryption' 10 | image_per=image(Pos); 11 | case 'Decryption' 12 | image_per(Pos)=image(:); 13 | end 14 | end -------------------------------------------------------------------------------- /Image_Diffusion.m: -------------------------------------------------------------------------------- 1 | function [DNA_image_encoded,key] = Image_Diffusion(DNA_image_permutasyon,m,n,x3,u3,Type) 2 | x(1) = x3; 3 | key(1)=floor(256*x(1)); 4 | for i = 2:m*n 5 | x(i)=mod(((exp(1)+u3))*log(x(i-1)),1); 6 | key(i)=floor(256*x(i)); 7 | end 8 | switch Type 9 | case 'Encryption' 10 | DNA_image_encoded=bitxor(DNA_image_permutasyon,key); 11 | case 'Decryption' 12 | DNA_image_encoded=bitxor(double(reshape(DNA_image_permutasyon,1,m*n)),key); 13 | end 14 | end -------------------------------------------------------------------------------- /NPCR_UACI.m: -------------------------------------------------------------------------------- 1 | function [npcr, uaci] = NPCR_UACI(ChiperImg,ChiperImg1bit) 2 | f1 = double(ChiperImg); 3 | f2 = double(ChiperImg1bit); 4 | [M, N] = size(f1); 5 | %% NPCR 6 | 7 | d = 0.000000; 8 | for i = 1 : M 9 | for j = 1 : N 10 | if f1(i, j) ~= f2(i, j) 11 | d = d + 1; 12 | end 13 | end 14 | end 15 | npcr = d / (M * N); 16 | 17 | %% UACI 18 | c = 0.000000; 19 | for i = 1 : M * N 20 | c = c + abs( double( f1(i)) - double( f2(i))); 21 | end 22 | uaci = c / (255 * M * N); 23 | -------------------------------------------------------------------------------- /Bit_Reversion.m: -------------------------------------------------------------------------------- 1 | function [I] = Bit_Reversion(I_D,m,n,x4,u4,Type) 2 | x(1) = x4; 3 | x1 = (0:255)'; 4 | v = bitrevorder(x1); 5 | for i = 2:m*n 6 | x(i)=mod(((exp(1)+u4))*log(x(i-1)),1); 7 | 8 | end 9 | x=floor(x*256); 10 | 11 | switch Type 12 | case 'Encryption' 13 | for i=1:m*n 14 | I(i)=v(x(i)+1); 15 | end 16 | I=bitxor(I_D,I); 17 | case 'Decryption' 18 | for i=1:m*n 19 | I(i)=v(x(i)+1); 20 | end 21 | I=bitxor(double(reshape(I_D,1,m*n)),I); 22 | end 23 | end -------------------------------------------------------------------------------- /AdjancyCorrPixelRand.m: -------------------------------------------------------------------------------- 1 | function CC=AdjancyCorrPixelRand(Encrypted) 2 | Encrypted=double(Encrypted); 3 | k = 50; 4 | [m,n] = size(Encrypted); 5 | m=m-1; 6 | n=n-1; 7 | s = randsample(m*n, k); 8 | [X, Y] = ind2sub([m, n], s); 9 | %% horizontal 10 | hxE = Encrypted(X,Y); 11 | hyE = Encrypted(X,Y+1); 12 | He_xy = corrcoef(hxE,hyE); 13 | CC(1,1)=He_xy(1,2); 14 | 15 | %% vertical 16 | vxE = Encrypted(X,Y); 17 | vyE = Encrypted(X+1,Y); 18 | Ve_xy = corrcoef(vxE,vyE); 19 | CC(2,1)=Ve_xy(1,2); 20 | %% diagonal 21 | dxE = Encrypted(X,Y); 22 | dyE = Encrypted(X+1,Y+1); 23 | De_xy = corrcoef(dxE,dyE); 24 | CC(3,1)=De_xy(1,2); 25 | end -------------------------------------------------------------------------------- /var_chi.m: -------------------------------------------------------------------------------- 1 | function [Var1 Var2 chi_2_Encryption chi_2_plain]=var_chi(I,I1) 2 | [m n]=size(I); 3 | [r1 c1]=imhist(I); 4 | [r2 c2]=imhist(I1); 5 | topla=0; 6 | topla2=0; 7 | for i=1:256 8 | for j=1:256 9 | topla=topla+0.5*(r1(i)-r1(j))^2; 10 | topla2=topla2+0.5*(r2(i)-r2(j))^2; 11 | end 12 | end 13 | Var1=topla/(256^2); 14 | Var2=topla2/(256^2); 15 | 16 | [r c]=imhist(I1); 17 | Var2=var(r(:)); 18 | 19 | topla=0; 20 | for i=1:256 21 | for j=1:256 22 | topla=topla+0.5*(r(i)-r(j))^2; 23 | end 24 | end 25 | Var3=topla/(256^2); 26 | 27 | topla=0; 28 | topla_2=0; 29 | piksel_say=m*n; 30 | for i=1:256 31 | topla=topla+((r(i)-(piksel_say/256))^2)/(piksel_say/256); 32 | topla_2=topla_2+((r1(i)-(piksel_say/256))^2)/(piksel_say/256); 33 | end 34 | chi_2_Encryption=topla; 35 | chi_2_plain=topla_2; 36 | end -------------------------------------------------------------------------------- /rule_2.m: -------------------------------------------------------------------------------- 1 | function [encoded_pixel_decimal] = rule_2(pixel_value,Type) 2 | encoded_pixel=[]; 3 | pixel_value_bin=dec2bin(pixel_value,8); 4 | 5 | switch Type 6 | case 'Encryption' 7 | for i=1:2:8 8 | a=pixel_value_bin(i:i+1); 9 | switch a 10 | case '00' 11 | encoded_pixel = [encoded_pixel '00']; 12 | case '01' 13 | encoded_pixel = [encoded_pixel '11']; 14 | case '10' 15 | encoded_pixel = [encoded_pixel '10']; 16 | case '11' 17 | encoded_pixel = [encoded_pixel '01']; 18 | end 19 | end 20 | 21 | case 'Decryption' 22 | for i=1:2:8 23 | a=pixel_value_bin(i:i+1); 24 | switch a 25 | case '00' 26 | encoded_pixel = [encoded_pixel '00']; 27 | case '11' 28 | encoded_pixel = [encoded_pixel '01']; 29 | case '10' 30 | encoded_pixel = [encoded_pixel '10']; 31 | case '01' 32 | encoded_pixel = [encoded_pixel '11']; 33 | end 34 | end 35 | end 36 | encoded_pixel_decimal=bin2dec(encoded_pixel); 37 | end -------------------------------------------------------------------------------- /rule_3.m: -------------------------------------------------------------------------------- 1 | function [encoded_pixel_decimal] = rule_3(pixel_value,Type) 2 | encoded_pixel=[]; 3 | pixel_value_bin=dec2bin(pixel_value,8); 4 | 5 | switch Type 6 | case 'Encryption' 7 | for i=1:2:8 8 | a=pixel_value_bin(i:i+1); 9 | switch a 10 | case '00' 11 | encoded_pixel = [encoded_pixel '10']; 12 | case '01' 13 | encoded_pixel = [encoded_pixel '00']; 14 | case '10' 15 | encoded_pixel = [encoded_pixel '01']; 16 | case '11' 17 | encoded_pixel = [encoded_pixel '11']; 18 | end 19 | end 20 | 21 | case 'Decryption' 22 | for i=1:2:8 23 | a=pixel_value_bin(i:i+1); 24 | switch a 25 | case '10' 26 | encoded_pixel = [encoded_pixel '00']; 27 | case '00' 28 | encoded_pixel = [encoded_pixel '01']; 29 | case '01' 30 | encoded_pixel = [encoded_pixel '10']; 31 | case '11' 32 | encoded_pixel = [encoded_pixel '11']; 33 | end 34 | end 35 | end 36 | encoded_pixel_decimal=bin2dec(encoded_pixel); 37 | end -------------------------------------------------------------------------------- /rule_4.m: -------------------------------------------------------------------------------- 1 | function [encoded_pixel_decimal] = rule_4(pixel_value,Type) 2 | encoded_pixel=[]; 3 | pixel_value_bin=dec2bin(pixel_value,8); 4 | 5 | switch Type 6 | case 'Encryption' 7 | for i=1:2:8 8 | a=pixel_value_bin(i:i+1); 9 | switch a 10 | case '00' 11 | encoded_pixel = [encoded_pixel '11']; 12 | case '01' 13 | encoded_pixel = [encoded_pixel '00']; 14 | case '10' 15 | encoded_pixel = [encoded_pixel '01']; 16 | case '11' 17 | encoded_pixel = [encoded_pixel '10']; 18 | end 19 | end 20 | 21 | case 'Decryption' 22 | for i=1:2:8 23 | a=pixel_value_bin(i:i+1); 24 | switch a 25 | case '11' 26 | encoded_pixel = [encoded_pixel '00']; 27 | case '00' 28 | encoded_pixel = [encoded_pixel '01']; 29 | case '01' 30 | encoded_pixel = [encoded_pixel '10']; 31 | case '10' 32 | encoded_pixel = [encoded_pixel '11']; 33 | end 34 | end 35 | end 36 | encoded_pixel_decimal=bin2dec(encoded_pixel); 37 | end -------------------------------------------------------------------------------- /rule_5.m: -------------------------------------------------------------------------------- 1 | function [encoded_pixel_decimal] = rule_5(pixel_value,Type) 2 | encoded_pixel=[]; 3 | pixel_value_bin=dec2bin(pixel_value,8); 4 | 5 | switch Type 6 | case 'Encryption' 7 | for i=1:2:8 8 | a=pixel_value_bin(i:i+1); 9 | switch a 10 | case '00' 11 | encoded_pixel = [encoded_pixel '10']; 12 | case '01' 13 | encoded_pixel = [encoded_pixel '01']; 14 | case '10' 15 | encoded_pixel = [encoded_pixel '00']; 16 | case '11' 17 | encoded_pixel = [encoded_pixel '11']; 18 | end 19 | end 20 | 21 | case 'Decryption' 22 | for i=1:2:8 23 | a=pixel_value_bin(i:i+1); 24 | switch a 25 | case '10' 26 | encoded_pixel = [encoded_pixel '00']; 27 | case '01' 28 | encoded_pixel = [encoded_pixel '01']; 29 | case '00' 30 | encoded_pixel = [encoded_pixel '10']; 31 | case '11' 32 | encoded_pixel = [encoded_pixel '11']; 33 | end 34 | end 35 | end 36 | encoded_pixel_decimal=bin2dec(encoded_pixel); 37 | end -------------------------------------------------------------------------------- /rule_7.m: -------------------------------------------------------------------------------- 1 | function [encoded_pixel_decimal] = rule_7(pixel_value,Type) 2 | encoded_pixel=[]; 3 | pixel_value_bin=dec2bin(pixel_value,8); 4 | switch Type 5 | case 'Encryption' 6 | for i=1:2:8 7 | a=pixel_value_bin(i:i+1); 8 | switch a 9 | case '00' 10 | encoded_pixel = [encoded_pixel '01']; 11 | case '01' 12 | encoded_pixel = [encoded_pixel '10']; 13 | case '10' 14 | encoded_pixel = [encoded_pixel '11']; 15 | case '11' 16 | encoded_pixel = [encoded_pixel '00']; 17 | end 18 | end 19 | 20 | case 'Decryption' 21 | for i=1:2:8 22 | a=pixel_value_bin(i:i+1); 23 | switch a 24 | case '01' 25 | encoded_pixel = [encoded_pixel '00']; 26 | case '10' 27 | encoded_pixel = [encoded_pixel '01']; 28 | case '11' 29 | encoded_pixel = [encoded_pixel '10']; 30 | case '00' 31 | encoded_pixel = [encoded_pixel '11']; 32 | end 33 | end 34 | end 35 | encoded_pixel_decimal=bin2dec(encoded_pixel); 36 | end 37 | -------------------------------------------------------------------------------- /rule_6.m: -------------------------------------------------------------------------------- 1 | function [encoded_pixel_decimal] = rule_6(pixel_value,Type) 2 | encoded_pixel=[]; 3 | pixel_value_bin=dec2bin(pixel_value,8); 4 | 5 | switch Type 6 | case 'Encryption' 7 | for i=1:2:8 8 | a=pixel_value_bin(i:i+1); 9 | switch a 10 | case '00' 11 | encoded_pixel = [encoded_pixel '11']; 12 | case '01' 13 | encoded_pixel = [encoded_pixel '01']; 14 | case '10' 15 | encoded_pixel = [encoded_pixel '00']; 16 | case '11' 17 | encoded_pixel = [encoded_pixel '10']; 18 | end 19 | end 20 | 21 | case 'Decryption' 22 | for i=1:2:8 23 | a=pixel_value_bin(i:i+1); 24 | switch a 25 | case '11' 26 | encoded_pixel = [encoded_pixel '00']; 27 | case '01' 28 | encoded_pixel = [encoded_pixel '01']; 29 | case '00' 30 | encoded_pixel = [encoded_pixel '10']; 31 | case '10' 32 | encoded_pixel = [encoded_pixel '11']; 33 | end 34 | end 35 | end 36 | encoded_pixel_decimal=bin2dec(encoded_pixel); 37 | end 38 | -------------------------------------------------------------------------------- /rule_8.m: -------------------------------------------------------------------------------- 1 | function [encoded_pixel_decimal] = rule_8(pixel_value,Type) 2 | encoded_pixel=[]; 3 | pixel_value_bin=dec2bin(pixel_value,8); 4 | 5 | switch Type 6 | case 'Encryption' 7 | 8 | for i=1:2:8 9 | a=pixel_value_bin(i:i+1); 10 | switch a 11 | case '00' 12 | encoded_pixel = [encoded_pixel '01']; 13 | case '01' 14 | encoded_pixel = [encoded_pixel '11']; 15 | case '10' 16 | encoded_pixel = [encoded_pixel '10']; 17 | case '11' 18 | encoded_pixel = [encoded_pixel '00']; 19 | end 20 | end 21 | 22 | case 'Decryption' 23 | for i=1:2:8 24 | a=pixel_value_bin(i:i+1); 25 | switch a 26 | case '01' 27 | encoded_pixel = [encoded_pixel '00']; 28 | case '11' 29 | encoded_pixel = [encoded_pixel '01']; 30 | case '10' 31 | encoded_pixel = [encoded_pixel '10']; 32 | case '00' 33 | encoded_pixel = [encoded_pixel '11']; 34 | end 35 | end 36 | end 37 | encoded_pixel_decimal=bin2dec(encoded_pixel); 38 | end -------------------------------------------------------------------------------- /rule_1.m: -------------------------------------------------------------------------------- 1 | function [encoded_pixel_decimal] = rule_1(pixel_value,Type) 2 | encoded_pixel=[]; 3 | pixel_value_bin=dec2bin(pixel_value,8); 4 | 5 | switch Type 6 | case 'Encryption' 7 | for i=1:2:8 8 | a=pixel_value_bin(i:i+1); 9 | switch a 10 | case '00' 11 | encoded_pixel = [encoded_pixel '00']; 12 | case '01' 13 | encoded_pixel = [encoded_pixel '10']; 14 | case '10' 15 | encoded_pixel = [encoded_pixel '11']; 16 | case '11' 17 | encoded_pixel = [encoded_pixel '01']; 18 | end 19 | end 20 | 21 | case 'Decryption' 22 | for i=1:2:8 23 | a=pixel_value_bin(i:i+1); 24 | switch a 25 | case '00' 26 | encoded_pixel = [encoded_pixel '00']; 27 | case '10' 28 | encoded_pixel = [encoded_pixel '01']; 29 | case '11' 30 | encoded_pixel = [encoded_pixel '10']; 31 | case '01' 32 | encoded_pixel = [encoded_pixel '11']; 33 | end 34 | end 35 | 36 | end 37 | encoded_pixel_decimal=bin2dec(encoded_pixel); 38 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## This code associated to the following preprint: 2 | 3 | ### _An Image Encryption Scheme Based on Chaotic Logarithmic Map and Key Generation using Deep CNN_ 4 | 5 | ## Cite as: 6 | 7 | Erkan U., Toktas A., Enginoğlu S., Karabacak E., Thanh DNH, An Image Encryption Scheme Based on Chaotic Logarithmic Map and Key Generation using Deep CNN, Preprint at [arXiv:2012.14156](https://arxiv.org/abs/2012.14156), 2020 8 | 9 | ## Abstract: 10 | 11 | A secure and reliable image encryption scheme is presented in this study. The encryption scheme hereby introduces a novel chaotic log-map, deep convolution neural network (CNN) model for key generation, and bit reversion operation for the manipulation process. Thanks to the sensitive key generation, initial values and control parameters are produced for the hyperchaotic log-map, and thus a diverse chaotic sequence is achieved for encrypting operations. The scheme then encrypts the images by scrambling and manipulating the pixels of images through four operations: permutation, DNA encoding, diffusion, and bit reversion. The encryption scheme is precisely examined for the well-known images in terms of various analyses such as keyspace, key sensitivity, information entropy, histogram, correlation, differential attack, noisy attack, and cropping attack. To corroborate the scheme, the visual and numerical results are even compared with available outcomes of the state of the art. Therefore, the proposed log-map based image encryption scheme is successfully verified and validated by the superior absolute and comparative results. 12 | -------------------------------------------------------------------------------- /DNA_Convert.m: -------------------------------------------------------------------------------- 1 | function [dna_image] = DNA_Convert(image,m,n,x2,u2,Type) 2 | x(1) = x2; 3 | switch Type 4 | case 'Encryption' 5 | load('DNA_Encryption.mat') 6 | 7 | for i = 1:(m*n) 8 | if(i>1) 9 | x(i)=mod(((exp(1)+u2))*log(x(i-1)),1); 10 | end 11 | Rule = ceil(7*x(i)) + 1; 12 | dna_image(i)=Encryption(image(i)+1,Rule); 13 | end 14 | case 'Decryption' 15 | load('DNA_Dencryption.mat') 16 | for i = 1:(m*n) 17 | if(i>1) 18 | x(i)=mod(((exp(1)+u2))*log(x(i-1)),1); 19 | end 20 | Rule = ceil(7*x(i)) + 1; 21 | dna_image(i)=Decryption(image(i)+1,Rule); 22 | 23 | % if(Rule==1) 24 | % dna_image(i) = rule_1(image(i),'Decryption'); 25 | % elseif(Rule==2) 26 | % dna_image(i) = rule_2(image(i),'Decryption'); 27 | % elseif(Rule==3) 28 | % dna_image(i) = rule_3(image(i),'Decryption'); 29 | % elseif(Rule==4) 30 | % dna_image(i) = rule_4(image(i),'Decryption'); 31 | % elseif(Rule==5) 32 | % dna_image(i) = rule_5(image(i),'Decryption'); 33 | % elseif(Rule==6) 34 | % dna_image(i) = rule_6(image(i),'Decryption'); 35 | % elseif(Rule==7) 36 | % dna_image(i) = rule_7(image(i),'Decryption'); 37 | % else 38 | % dna_image(i) = rule_8(image(i),'Decryption'); 39 | % end 40 | % switch Rule 41 | % case 1 42 | % dna_image(i) = rule_1(image(i),'Decryption') 43 | % case 2 44 | % dna_image(i) = rule_2(image(i),'Decryption') 45 | % case 3 46 | % dna_image(i) = rule_3(image(i),'Decryption') 47 | % case 4 48 | % dna_image(i) = rule_4(image(i),'Decryption') 49 | % case 5 50 | % dna_image(i) = rule_5(image(i),'Decryption') 51 | % case 6 52 | % dna_image(i) = rule_6(image(i),'Decryption') 53 | % case 7 54 | % dna_image(i) = rule_7(image(i),'Decryption') 55 | % case 8 56 | % dna_image(i) = rule_8(image(i),'Decryption') 57 | % end 58 | end 59 | end 60 | end -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | clc;clear all;close all; 2 | A=imread("lena_512.tif"); 3 | 4 | D=[0 1 0 1 0 1 1 0 0 0 1 1 1 0 0 1 0 1 1 1 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 1 0 0 1 0 1 1 1 0 0 1 0 1 1 0 1 0 0 1 1 1 0 0 1 0 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 1 1 1 0 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 1 0 0 1 0 0 0 1 0 1 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 1 1 1 1 1 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1 1 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0 1 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 1 0 1 1 0 1 0 1 0 1 1 0 0 1 0 1 1 1 0 0 0 1]; 5 | 6 | [m n]=size(A); 7 | 8 | tic 9 | J = imresize(A, [224 224]); 10 | imwrite(J, 'resized/deneme.tif'); 11 | system('C:\Users\User\.conda\envs\py35\pythonw Python3\run_512_GrayScale_v2.py'); 12 | B = importdata('hashCodes/hashCodes_512.txt')'; 13 | C=logical(B); 14 | 15 | %Encryption 16 | tic 17 | [V,U]=start_point_calcalutor(C,D); 18 | [Img_Prmt]=Image_Permutation(A,m,n,V(1),U(1),'Encryption'); 19 | [DNA_Img]=DNA_Convert(Img_Prmt,m,n,V(2),U(2),'Encryption'); 20 | [Img_Diff]=Image_Diffusion(DNA_Img,m,n,V(3),U(3),'Encryption'); 21 | Bit_Reversion_Img= Bit_Reversion(Img_Diff,m,n,V(4),U(4),'Encryption'); 22 | Enc_Img=uint8(reshape(Bit_Reversion_Img,m,n)); 23 | Enc_Time = toc; 24 | 25 | %Decryption 26 | tic 27 | [V,U]=start_point_calcalutor(C,D); 28 | De_Bit_Reversion_Img= Bit_Reversion(Enc_Img,m,n,V(4),U(4),'Decryption') ; 29 | De_Img_Diffusion=Image_Diffusion(De_Bit_Reversion_Img,m,n,V(3),U(3),'Decryption'); 30 | De_DNA_Img=DNA_Convert(De_Img_Diffusion,m,n,V(2),U(2),'Decryption'); 31 | De_Img_Prmt=Image_Permutation(De_DNA_Img,m,n,V(1),U(1),'Decryption'); 32 | De_Enc_Img=uint8(reshape(De_Img_Prmt,m,n)); 33 | zaman_3 = toc; 34 | 35 | %Correlation 36 | Correlation_Corr=AdjancyCorrPixelRand(Enc_Img); 37 | %Entropi 38 | H=entropy(Enc_Img); 39 | %npcr1, uaci calculate 40 | A1bit=A; 41 | r=randi([1 m],1,2); 42 | A1bit(r(1),r(2)) =mod(A(r(1),r(2))+1,255); 43 | J1Bit = imresize(A1bit, [224 224]); 44 | imwrite(J1Bit, 'resized/deneme.tif'); 45 | system('C:\Users\User\.conda\envs\py35\pythonw Python3\run_512_GrayScale_v2.py'); 46 | B1Bit = importdata('hashCodes/hashCodes_512.txt')'; 47 | C1Bit=logical(B1Bit); 48 | [V1Bit,U1Bit]=start_point_calcalutor(C1Bit,D); 49 | [Image_Prmt_1Bit]=Image_Permutation(A1bit,m,n,V1Bit(1),U1Bit(1),'Encryption'); 50 | [DNA_Img_1Bit]=DNA_Convert(Image_Prmt_1Bit,m,n,V1Bit(2),U1Bit(2),'Encryption'); 51 | [Img_Diff_1Bit]=Image_Diffusion(DNA_Img_1Bit,m,n,V1Bit(3),U1Bit(3),'Encryption'); 52 | Bit_Reversion_Img_1Bit= Bit_Reversion(Img_Diff_1Bit,m,n,V1Bit(4),U1Bit(4),'Encryption'); 53 | Enc_Img_1Bit=uint8(reshape(Bit_Reversion_Img_1Bit,m,n)); 54 | [npcr, uaci]= NPCR_UACI(uint8(Enc_Img),uint8(Enc_Img_1Bit)); 55 | 56 | 57 | %croppimg attack 58 | Crop_Ratio=16; 59 | 60 | Enc_Img_Crop=Enc_Img; 61 | if Crop_Ratio==2 62 | Enc_Img_Crop(1:512, 1:256)=0; 63 | elseif Crop_Ratio==4 64 | Enc_Img_Crop(1:256, 1:256)=0; 65 | elseif Crop_Ratio==16 66 | Enc_Img_Crop(1:128, 1:128)=0; 67 | elseif Crop_Ratio==32 68 | Enc_Img_Crop(1:64, 1:64)=0; 69 | end 70 | De_Bit_Reversion_Img_Crop= Bit_Reversion(Enc_Img_Crop,m,n,V(4),U(4),'Decryption') ; 71 | De_Image_Diffusion_Crop=Image_Diffusion(De_Bit_Reversion_Img_Crop,m,n,V(3),U(3),'Decryption'); 72 | De_DNA_Image_Crop=DNA_Convert(De_Image_Diffusion_Crop,m,n,V(2),U(2),'Decryption'); 73 | De_Image_Prmt_Crop=Image_Permutation(De_DNA_Image_Crop,m,n,V(1),U(1),'Decryption'); 74 | DE_Enc_Img_Crop=uint8(reshape(De_Image_Prmt_Crop,m,n)); 75 | PSNR_Crop=psnr(A,DE_Enc_Img_Crop); 76 | 77 | %noise attack 78 | NoiseLevel=0.001; 79 | Enc_Img_Noise=double(imnoise(Enc_Img,'salt & pepper',NoiseLevel)); 80 | De_Bit_Reversion_Noise= Bit_Reversion(Enc_Img_Noise,m,n,V(4),U(4),'Decryption') ; 81 | De_Image_Diffusion_Noise=Image_Diffusion(De_Bit_Reversion_Noise,m,n,V(3),U(3),'Decryption'); 82 | De_DNA_Image_Noise=DNA_Convert(De_Image_Diffusion_Noise,m,n,V(2),U(2),'Decryption'); 83 | De_Image_Prmt_Noise=Image_Permutation(De_DNA_Image_Noise,m,n,V(1),U(1),'Decryption'); 84 | De_Enc_Img_Noise=uint8(reshape(De_Image_Prmt_Noise,m,n)); 85 | PSNR_Nosie=psnr(A,De_Enc_Img_Noise); 86 | 87 | %variance and chi_2 88 | [Plain_Variance Enc_Variance chi_2_Enc chi_2_plain]=var_chi(A,Enc_Img) 89 | z_Var1=Plain_Variance; 90 | z_Var2=Enc_Variance; 91 | z_chi_2_Encryption=chi_2_Enc; 92 | z_chi_2_plain=chi_2_plain; 93 | 94 | --------------------------------------------------------------------------------