You are on page 1of 6

Cryptography Using Chaotic Neural Network Based On Image Processing

INTRODUCTION
A neural network is a machine that is designed to model the way in which the brain
performs a particular task. The network is implemented by using electronic components or is simulated in
software on a digital computer.in our work we are using the same method to encrypt the image using
neural network. By ensuring that the image that is encrypted by the process must have its inverse value
that is use to decrypt the image using same phenomena.

Chaos is statistically indistinguishable from randomness, and yet it is deterministic and not
random at all. Chaotic system will produce the same results if given the same inputs, it is unpredictable in
the sense that you cannot predict in what way the system's behavior will change for any change in the
input to that system. A random system will produce different results when given the same inputs.
Chaotic neural networks offer greatly increase memory capacity. Each memory is encoded
by an Unstable Periodic Orbit (UPO) on the chaotic attractor. A chaotic attractor is a set of states in a
system's state space with very special property that the set is an attracting set. So the system starting with its
initial condition in the appropriate basin, eventually ends up in the set. The most important, once the system
is on the attractor nearby states diverge from each other exponentially fast, however small amounts of noise
are amplified.

A new chaotic neural network for digital signal encryption and decryption was studied in
this project. According to a binary sequence generated from a chaotic system, the biases and
weights of neurons are set. The chaotic neural network can be used to encrypt digital signal. The
network's features are as follows:

1) High security
2) No distortion
3) Suitable for system integration.

As purposed encryption technique , there are three basic classification:

a. Permutation
b. Transformation
c. Combining

Proposed Cryptosystem
A network is called a chaotic neural network if its weights and biases are determined by a chaotic
sequence. Let g denote a digital signal of length M and g(n), 0 ≤ M-1 , be the one-byte value of the signal g
at position n.

 Select the image(a) for encryption.


 Convert the image into gray scale(g).
 Get the image pixel value and store it in an array.
 Resize the image by giving mxn dimensions.
 Determine the parameter, U and the initial point x(0) of the 1-D logistic map [SI.
 Evolve the chaotic sequence x(l), x(2), ... , x(M) by x(n+l) = μ(n)(l-x(n)), and create b(O), b(l), ...,
b(8M-1) from x(l), x(2), ..., x(M) by the generating scheme that 0.b(8m-8)b(8m-7) ….. b(8m-2)b(8m-
l) … is the binary representation of x(m) for m = 1, 2,. . . ., M.
 Permute the pixel values in a random reverse able order using cnn.
 The encrypted signal g‟ is obtained and the algorithm is terminated.

The decryption procedure is the same as the above one except that the input signal to the decryption CNN
should be g’(n) and its output signal should be g”(n).
Assume the encryption procedure is known except the chaotic binary sequence. When the CNN is applied
to a signal of length M, it requires 8M bits. The number of possible encryption results is 28×M. Let us
consider the raw data of size 65536 bytes. 8M equals 524288 and all the possible results are 252428(≈
10157810). In the chaotic systems, it is well-known that

1) It has sensitive dependence on initial conditions


2) There exist trajectories that are dense, bounded, but neither periodic nor quasi-periodic in the state space.

Hence, the chaotic binary sequence is unpredictable. It is very difficult to decrypt an encrypted image
correctly by making an exhaustive search without knowing x(0) and μ. Hence, CNN is one of guaranteed
high security.

Image Encryption

CODE
clc;
L=255;
W=255;
inputimage= imread('lena.png');

a=inputimage;

g=rgb2gray(a);
g=imresize(g,[L,W]);

b=reshape(g.', 1, []);

[count,x] = imhist(b); % select one of 3 channels


i=[count,x];

dlmwrite('ORG.dat', b);

filename = 'ORG.dat';%file for decryption.


[A,delimiterOut]=importdata(filename);
or = reshape(A,L,W)
dlmwrite('orignalimg.dat', or);
grayImage = uint8(importdata('orignalimg.dat'));
imwrite(grayImage, 'orgimg.png');
% input -------------------------------------------------------------------
inp=A

for i=1:length(inp);
inpx(i,:)=bitget(inp(i),8:-1:1);
end

% generating a chaotic sequence -------------------------------------------

l=length(inp);
x(1)=0.75;
mu=3.9

for i=2:l
x(i)=mu*x(i-1)*(1-x(i-1));
end

x=uint8(((x-min(x))/max(x))*255);
b=[];

for i=1:l
b(i,:)= bitget(x(i),8:-1:1);
end

temp=0;
outx=zeros(1,length(inp));
% network -----------------------------------------------------------------
for c=1:length(inp);

for i=1:8

for j=1:8

if (b(c,i)==0)&(i==j)
weight(i,j)=1;
elseif (b(c,i)==1)&(i==j)
weight(i,j)=-1;
elseif i~=j
weight(i,j)=0;
end
end

if (b(c,i)==0)
theta(i)=-1/2;
else theta(i)=1/2;
end
end
for i=1:8

dx(c,i) = hardlim(sum(weight(i,:).*inpx(c,:))+theta(i));
end
for i=1:8

outx(c)=outx(c)+uint8(dx(c,i))*(2^(8-i));
end
end

outx
dlmwrite('ENCR.dat', outx);
mt = reshape(outx,L,W)
dlmwrite('out.dat', mt);
grayImage = uint8(importdata('out.dat'));
imwrite(grayImage, 'myimage.png');
[X1,map1]=imread('orgimg.png');
[X2,map2]=imread('myimage.png');
subplot(1,2,1), imshow(X1,map1)
subplot(1,2,2), imshow(X2,map2)

Origrnal pixels of grey scale image:


157,160,156,102,105,117,129,131,133,133,131,131,132,129,127,116,148,158,154,165
,185,116,122,128,96,159,165,150,100,103,116,127,129,130,129,125,125,127,127,127
,115,138,161,157,150,185,154,120,90,48,162,153,152,96,102,116,125,128,129,134,1
50,163,153,127,122,114,131,152,153,145,150,200,93,47,47,137,134,154,91,100,112,
122,123,122,131,148,179,194,183,129,102,134,143,141,144,146,137,54,47,62,97,133
,154,92,100,111,120,114,119,133,141,173,197,209,200,107,131,134,97,144,136,59,4
6,61,132,87,133,153,90,99,112,123,111,127,133,150,184,195,201,210,185,131,132,6
6,173,106,45,50,115,162,95,134,156,91,99,118,128,109,124,140,169,179,183,192,19
5,203,171,151,175,221,118,39,85,158,157,96,137,161,93,96,121,145,109,131,144,15
8,170,172,179,180,178,189,201,206,190,84,53,141,161,157,96,140,162,93,95,120,16
7,121,131,138,138,126,131,116,157,190,199,198,164,129,48,99,161,157,155,101,140
,162,92,96,109,170,127,128,121,85,70,76,115,181,190,164,140,132,65,53,141,165,1
58,154,101,134,164,92,97,104,155,129,112,71,65,57,110,179,176,197,142,104,70,46
,82,157,163,161,155,98,133,166,95,101,112,128,115,66,54,60,110,176,161,175,206,
176,79,68,51,121,162,155,152,150,95,131,167,95,97,131,110,81,64,52,81,172,115,1
00,147,174,102,72,75,62,146,158,156,150,139,90,124,171,100,107,114,78,83,68,47,
141,149,118,144,141,162,94,71,78,85,156,153,148,147,168,75,117,171,104,112,82,7
4,66,79,91,123,125,170,166,141,182,123,72,79,114,157,147,143,184,200,70,114,169
,105,95,88,81,60,85,114,70,125,154,154,128,171,106,61,95,139,153,143,164,203,20
7,69,127,170,104,86,74,96,93,121,67,72,126,143,144,154,160,71,60,111,152,149,14
1,182,210,211,57,130,173,108,75,85,99,142,90,49,66,108,136,128,144,111,51,66,12
0,158,150,139,195,214,215,49,130,171,98,64,84,114,111,55,53,55,70,115,149,160,7
7,50,76,121,148,147,138,204,214,165,84,109,173,98,60,79,99,115,76,53,53,74,123,
141,165,175,109,71,121,131,117,125,207,139,72,119,118,176,86,54,64,73,114,99,55
,59,87,129,142,160,188,211,103,121,146,128,161,188,93,99,98,125,175,78,53,59,58
,106,101,62,74,104,133,139,152,175,209,171,130,144,137,207,149,97,97,90,131,173
,83,50,55,61,91,73,50,95,111,141,138,145,164,196,205,119,113,136,188,109,92,88,
111,141,171,78,49,60,59,92,52,59,96,126,141,142,140,153,181,211,131,77,125,134,
77,94,79,96,160,166,67,58,73,77,75,61,93,123,133,138,144,145,150,170,203,159,10
3,120,94,86,98,68
Encrypted image pixels:
54,6,44,248,215,9,96,144,241,97,133,209,89,158,236,185,192,65,128,35,99,95,209,
40,205,61,18,24,183,37,186,46,92,163,22,181,28,154,123,51,170,167,14,3,40,199,1
22,109,33,210,178,246,126,97,37,187,49,89,175,55,10,98,237,155,124,32,94,135,10
,92,196,22,67,191,254,192,80,162,154,17,148,125,47,165,153,19,105,238,26,35,208
,9,93,200,65,212,90,118,227,105,128,145,226,191,111,15,157,119,56,94,170,9,113,
66,4,61,99,144,31,112,157,64,204,45,233,177,133,217,150,53,144,109,17,159,144,2
37,90,204,162,52,185,188,79,24,79,100,68,212,115,157,148,220,126,86,4,144,129,4
4,177,216,118,169,48,25,237,123,54,87,214,62,122,68,176,157,218,180,182,107,6,1
31,117,242,136,128,216,75,151,100,208,82,176,251,26,140,112,5,232,172,57,90,6,1
06,163,31,145,40,123,90,31,75,252,154,139,34,125,168,187,39,182,243,213,103,234
,69,169,210,0,118,97,168,15,79,124,201,175,108,132,62,150,182,247,114,187,68,57
,214,134,250,123,156,52,91,133,202,168,54,127,134,38,167,87,71,142,166,203,39,1
29,4,160,46,18,86,250,67,139,12,99,167,29,170,63,91,84,225,131,173,161,254,122,
135,104,1,212,134,64,156,166,215,65,184,239,31,103,40,130,137,51,181,73,111,178
,160,17,129,151,228,177,124,241,184,73,182,58,38,23,154,11,72,110,55,145,68,14,
160,38,214,118,122,243,104,161,22,146,114,146,249,127,149,208,120,7,172,133,218
,234,150,39,164,79,27,183,43,74,176,240,87,111,49,172,126,255,118,140,241,30,11
3,178,209,138,85,6,181,59,0,146,81,2,122,141,0,116,115,187,132,163,63,63,57,11,
183,166,116,245,140,80,24,189,66,234,142,27,161,148,25,77,147,254,180,182,182,3
6,23,117,189,53,56,193,125,39,147,103,212,0,137,115,140,61,85,162,8,169,91,164,
120,222,93,211,34,199,167,215,128,237,177,3,155,63,181,27,152,148,240,227,69,23
4,154,6,247,252,72,181,43,117,94,125,100,217,57,169,101,173,108,31,170,53,117,1
34,35,108,180,222,136,68,49,86,78,184,165,109,72,72,189,235,181,58,36,175,112,3
8,229,126,134,199,93,224,112,133,135,108,233,98,176,211,187,97,38,173,229,153,0
,134,186,181,124,187,145,78,39,51,19,122,235,104,237,118,136,140,69,42,185,106,
54,63,157,99,234,31,195,143,90,185,111,205,65,201,70,213,162,145,115,204,109,36
,138,97,172,252,78,76,119,239,123,144,98,219,118,0,109,155,247,123,165,190,101,
76,60,75,24,129,87,226,125,134,214,241,19,174,70,91,187,122,196,68,193,76,182,6
3,0,197,132,117,56,176,99,6
Decrypted image pixels:
157,160,156,102,105,117,129,131,133,133,131,131,132,129,127,116,148,158,154,165
,185,116,122,128,96,159,165,150,100,103,116,127,129,130,129,125,125,127,127,127
,115,138,161,157,150,185,154,120,90,48,162,153,152,96,102,116,125,128,129,134,1
50,163,153,127,122,114,131,152,153,145,150,200,93,47,47,137,134,154,91,100,112,
122,123,122,131,148,179,194,183,129,102,134,143,141,144,146,137,54,47,62,97,133
,154,92,100,111,120,114,119,133,141,173,197,209,200,107,131,134,97,144,136,59,4
6,61,132,87,133,153,90,99,112,123,111,127,133,150,184,195,201,210,185,131,132,6
6,173,106,45,50,115,162,95,134,156,91,99,118,128,109,124,140,169,179,183,192,19
5,203,171,151,175,221,118,39,85,158,157,96,137,161,93,96,121,145,109,131,144,15
8,170,172,179,180,178,189,201,206,190,84,53,141,161,157,96,140,162,93,95,120,16
7,121,131,138,138,126,131,116,157,190,199,198,164,129,48,99,161,157,155,101,140
,162,92,96,109,170,127,128,121,85,70,76,115,181,190,164,140,132,65,53,141,165,1
58,154,101,134,164,92,97,104,155,129,112,71,65,57,110,179,176,197,142,104,70,46
,82,157,163,161,155,98,133,166,95,101,112,128,115,66,54,60,110,176,161,175,206,
176,79,68,51,121,162,155,152,150,95,131,167,95,97,131,110,81,64,52,81,172,115,1
00,147,174,102,72,75,62,146,158,156,150,139,90,124,171,100,107,114,78,83,68,47,
141,149,118,144,141,162,94,71,78,85,156,153,148,147,168,75,117,171,104,112,82,7
4,66,79,91,123,125,170,166,141,182,123,72,79,114,157,147,143,184,200,70,114,169
,105,95,88,81,60,85,114,70,125,154,154,128,171,106,61,95,139,153,143,164,203,20
7,69,127,170,104,86,74,96,93,121,67,72,126,143,144,154,160,71,60,111,152,149,14
1,182,210,211,57,130,173,108,75,85,99,142,90,49,66,108,136,128,144,111,51,66,12
0,158,150,139,195,214,215,49,130,171,98,64,84,114,111,55,53,55,70,115,149,160,7
7,50,76,121,148,147,138,204,214,165,84,109,173,98,60,79,99,115,76,53,53,74,123,
141,165,175,109,71,121,131,117,125,207,139,72,119,118,176,86,54,64,73,114,99,55
,59,87,129,142,160,188,211,103,121,146,128,161,188,93,99,98,125,175,78,53,59,58
,106,101,62,74,104,133,139,152,175,209,171,130,144,137,207,149,97,97,90,131,173
,83,50,55,61,91,73,50,95,111,141,138,145,164,196,205,119,113,136,188,109,92,88,
111,141,171,78,49,60,59,92,52,59,96,126,141,142,140,153,181,211,131,77,125,134,
77,94,79,96,160,166,67,58,73,77,75,61,93,123,133,138,144,145,150,170,203,159,10
3,120,94,86,98,68

You might also like