You are on page 1of 11

Simulation of optical XOR encryption using MATLAB

Prof. MTE Kahn and Bo Zhang

Abstract.

In this paper, we describe an optical security device that is the exclusive-OR (XOR)
encryption. In the field of electronic ciphering, one such algorithm is the exclusive-
OR encryption. This encryption technique can handle only binary signals and encrypts
each pixel individually. Because images consist of pixel, we can use mask bit to
encrypt it. The theoretical results are verified by computer simulation. Theoretical and
computer simulation indicate that XOR encryption is a safe coding method.

Keyword: XOR encryption, optical encryption, MSE, LCD, CCD, LED

1 Introduction

Recently, optical information processing methods have been proposed for information
security applications. Optical encryption techniques seem to be promising for security
applications because they take advantage of high-resolution optical materials,
enabling us to store a considerable amount of data in a small area, which would record
personal biometrics and financial data like fingerprints. These security systems
determine authenticity of the input by comparing the output image. We propose an
optical security system that is based on optical XOR encryption.

In our method, a two-input exclusive-or (XOR) gate can be implemented very simply
using two polarizers and two liquid crystal displays (Figure 1)[Han J-W., Park C-S.,
Ryu D-H., and Kim E-S. (1999)] as follows. Note first that an LCD that is switched
on will rotate light by 90 o , while one that is switched off will simply pass the light.
One arbitrary polarization (in this case, horizontal) is designated to be 1, while the
other (vertical) is zero. Unpolarized light is then passed through a “0” polarizer, then
through two LCDs which are either on or off depending on their input value, and then
outputted through a “1” polarizer. If the light passes through exactly one LCD which
is switched on, it will be able to pass through the output polarizer and is considered a
1 output. If it passes through either zero or two polarizers which are switched on, it
will not be able to pass through the output polarizer and will be considered a 0. It is
evident that this scheme can be trivially extended to an arbitrary number of inputs. All
other logic gates can also be implemented optically. The reader is directed to [Khan
and Nejib (1987)] for more details.

1
2 Polarization Encoding

Recently, LCDs have been used in a number of optical processing applications,


mainly as a spatial light intensity modulator, also acts as a spatial phase modulator.
Both intensity modulation and phase modulation are dependent on the applied voltage
and on the orientations of the polarizers. The liquid crystal molecules are sandwiched
between two layers of transparent electrodes. The electric field can b applied between
these electrodes. Each liquid crystal cell of the LCD is a nematic liquid crystal twisted
90 deg. When no electric field is applied, the plane of polarization for linearly
polarized light is rotated through 90 deg by the twisted liquid crystal molecules. Thus,
no light can be transmitted through the analyzer. Under an electric field, however, the
twist and tilt of the molecules are altered, and the liquid crystal molecules attempt to
align parallel with the applied field. This results in partial transmission of light
through the analyzer. As the electric field increases further, all the liquid crystal
molecules align in the direction of the applied field. This property of the LCD can be
used to implement Boolean logic. Great process has been made in the logic operations
using polarization encoding of the LCD, and the properties of the LCD are used to
achieve all possible 2-operand Boolean algebra functions [Yu F. T. S., Jutamulia, and
Gregory D. A. (1987)].

The applied electric field that decides the rotation of the input polarization is
controlled by a gray-level value represented on the LCD. The gray-level value, which
represents a logic state, can be determined by measuring the rotation angle of the
polarization. In this paper, the gray level that changes the direction of input
polarization by 90 deg is defined as logic 1 and one that does not rotate the input
polarization is defined as logic 0.

An XOR function using two LCDs is illustrated in Fig. 1, where the polarizer, two
LCDs, and the analyzer are arranged in series. The original polarizer of two LCDs
should be removed. The orientation of the polarizer is perpendicular to that of the
analyzer and the input light has vertical polarization. The analyzer, which is
placedafter LCD 2, converts the polarization information to intensity information
LCDs labeled 1, which rotate the polarization state, are equivalent to logic 1 and
LCDs labeled 0, which do not rotate the polarization state, indicate logic 0. If the state
of the LCD is logic 1, the output polarization of the LCD becomes the horizontal due
to the twisted liquid crystal molecules. And if the state of the LCD is logic 0, the
output polarization of the LCD remains the same. The result is 0 (no light) when same
logic states are represented on two LCDs and is 1 (light) when different logic states
are represented on two LCDs. As a result, a combination of two LCDs is capable of
performing XOR logical operations, as shown in Fig. 1.

The optical XOR operations between the key bit stream and the bit planes are
performed by the polarization encoding method, as shown in Fig. 1. The input image
is converted to binary digitally and the binary image is represented on LCD2. The key
bit stream generated b y digital encryption algorithms is represented on LCD 1. the
XOR operations are performed by the polarization, as shown in Fig. 1.

2
Figure 1 Two-input optical XOR gate with possible states

3 XOR Encryption Techniques

This encryption technique can handle only binary signals and it encrypts each pixel
(bit) individually. This method uses the XOR Boolean operator [Javidi B. and Horner
J. L. (1994)], defined for binary inputs, and which has the following property:

( aXORb ) XORb = a. (1)

The XOR encryption is based on the following property: let o(l ) be the bit we wish to
cipher, and k (l ) the corresponding bit from the key. The key k (l ) is a binary vector.
To make the key difficult to decode, the distribution of 1’s and 0’s should be equal
and they should be randomly located. The encrypted bit is given by

e(l ) = o(l ) XORk (l ). (2)

To decrypt, we simply use the fact that

o(l ) = e(l ) XORk (l ). (3)

The operations for the encryption and decryption are identical, as shown in Fig. 2.

3
(a)

(b)

(c)

Figure 2 Model of XOR encryption and decryption

4 XOR Encryption Technique in the presence of additive noise

We evaluate the MSE (mean square error) when noise is added to the encrypted image
obtained by the XOR encryption method.

Let o(l ) denote the original value of the pixel, k (l ) the value of the key, e(l ) the
value of the encrypted bit, and r (l ) the recovered value. The problem is formulated as
follows.

The encrypted image is given by e( L) = o(l ) XORk (l ) . Noise n (l ) is added to the


encrypted image to produce e(l ) + n (l ) , and e(l ) + n (l ) is thresholded by t (.) before
the decryption. The recovered image is

r (l ) = t[e(l ) + n (l )] XORk (l ) . (4)

4
The MSE is

MSE = E{[r (l ) − o(l )]2 } (5)

where r (l ) and o(l ) are the recovered and the original images, respectively.

By applying Bayes theorem, we have

E{[ r (l ) − o(l )]2 } = E{[r (l ) − o(l )]2 | o(l ) = 0, k (l ) = 0] X P[o(l ) = 0, k (l ) = 0]


+ E{[r (l ) − o(l )]2 | o(l ) = 0, k (l ) = 1] X P[o(l ) = 0, k (l ) = 1] (6)
+ E{[r (l ) − o(l )]2 | o(l ) = 1, k (l ) = 0] X P[o(l ) = 1, k (l ) = 0]
+ E{[r (l ) − o(l )]2 | o(l ) = 1, k (l ) = 1] X P[o(l ) = 1, k (l ) = 1] ,

where E{ X | Y } is the conditional expected value of X given Y , and P ( X , Y )


is the joint probability of X and Y.

We now compute the conditional expectation, in the case that o = 0 and k = 1 . Using
Eq. (4), we can see that e(l ) = o(l ) XORk (l ) = 0 XOR1 = 1 , and r (l ) = t[1 + n (l )] XOR1 .

The XOR operator is such that, when a is binary valued, aXOR1 = 1 − a . Hence,

r (l ) = 1 − t[1 + n (l )] . (7)

The square error is

[ r (l ) − o(l )]2 = {1 − t[1 + n(l )] − 0}2


= 1 − 2t[1 + n(l )] + {t[1 + n(l )]}2 . (8)

Using the property that a 2 = a when a is a binary valued, we have

[ r (l ) − o(l )]2 = 1 − t[1 + n(l )] . (9)

The conditional MSE for o(l ) = 0 and k (l ) = 1 is

E{[ r (l ) − o(l )]2 | o(l ) = 0, k (l ) = 1} = 1 − E{t[1 + n(l )]} . (10)

A similar calculation can be used to compute the conditional expectation for the other
possible values of o(l ) and k (l ) . The results are summarized in Table 1.

Table 1 The MSE for different possible values of the image and the key in presence
of additive noise.

o(l ) k (l ) e(l ) = o(l ) XORk (l ) e(l ) + n (l ) t[e(l ) + n (l )] r (l ) [ r (l ) − o(l )]2 E{[r (l ) − o(l )]2 | o(l ), k (l )

0 0 0 n (l ) t[n (l )] t[n (l )] t[n (l )] E{t[n (l )]}

5
0 1 1 1 + n(l ) t[1 + n (l )] 1 − t[1 + n (l )] 1 − t[1 + n (l )] 1 − E{t[1 + n (l )]}
1 0 1 1 + n(l ) t[1 + n (l )] t[1 + n(l )] 1 − t[1 + n (l )] 1 − E{t[1 + n (l )]}
1 1 0 n (l ) t[n (l )] 1 − t[n (l )] t[n (l )] E{t[n (l )]}

5 Computer Simulations

Simulations were performed to verify the validity of the proposed scheme for image
encryption. The simulations were carried out on a PC Matlab platform. The validity of
the proposed encryption method was investigated using the “Board” image as the
input image. Figure 3 describes the input images for computer simulations.

Simulations processing:

1. Display an image in Matlab.


2. Turn the colour image into a binary image.
3. According to large of image, giving key-bit.
4. Cause key-bit XOR the binary image. Getting an encryption image.
5. Cause the transformed image XOR key-bit again, you can get the binary image
again. This processing is decryption.
6. Compare the original image with the decryption image.

Fig. 3(a) is the input image and Fig. 3(b) is the key bit stream. The size of the input
image was 648X306 pixels and the size of the key bit stream was also bit arrays. The
random key bit stream is generated by a digital generator. The input gray-level image
and key bit stream arrays should be converted to the binary image, as shown in Fig.
3(c) (d). As mentioned, the proposed method is that the input image is encrypted by
performing XOR operation with the key bit stream. We can see the result in Fig. 3(e)
that the binary image has been well encrypted into the random key bit stream arrays.
The decrypted binary image was also obtained using the same key bit stream as
shown in Fig. 3(f). The resultant output image was converted to the decrypted gray-
level image, as shown in Fig. 3(g). It is obvious from comparing Fig. 3(a) with Fig.
3(g) that they are some different. But the binary images are the same before and after
XOR with key bit stream, as shown in Fig. 3(c)(f). Because that lose a little
information when the input gray-level image was converted to binary image.
Therefore, decrypted gray-level image are some different with input gray-level image,
as shown in Fig. 3(a)(g).

Figure 4 shows the histogram number of gray levels used to represent the images
shown in Fig. 3(a)(b)(c)(g). Figure 4(a) is the histogram of the input gray-level image.
Figure 4(c) is the binary image gray levels. We can see that processing was lost a lot
of information about details of gray levels. So when we got decrypted image that was
less gray levels than the original image’s.

Our simulations were carried out based on the ideal system. In computer simulations,
we did not consider problems such as a shift, scale change, rotation, ect. However,
these problems can happen in real situations. Using a variety of filters that have been
widely used in image recognition can reduce these various errors in the input image.
Therefore, we limit our attention to the ideal system and present some simulation
results.

6
For example:

One time pad


Binary Image plaintext = 010010101010111101001110010…
To encrypt: XOR
Key-bit = 110011010010101000010101000…
Cipher text = 100001111000010101011011010… (11)
To decrypt: XOR
Key-bit = 110011010010101000010101000…
Decrypted = 010010101010111101001110010…

The mechanism of the one time pad [Frank Stajano (1998)] is very simple: XOR
every plaintext bit with the corresponding random key bit to yield a ciphertext bit:
c = p k.
To decrypt, XOR the ciphertext with the key once more: d = c k. The two keys
will cancel out and you’ll get the plaintext.

The one time pad is the only demonstrably secure cipher, in the sense that even an
infinite amount of ciphertext will not leak any bits of information to the attacker about
the plaintext (except the length). This is because, given a ciphertext, you can choose
any plaintext you want and there will always exist a key that generates that ciphertext
from that plaintext. Why do people ever use anything else, then? Well, the one time
pad is not very practical because it requires a lot of key material (as many key bits as
message bits). You can’t ever reuse the same key bits and you must use a truly
random source; otherwise, cryptanalytic attacks become possible. If you use a pseudo-
random number generator, you instead obtain what is known as a stream cipher.

(a) (b) (c) (d)

7
(e) (f) (g)

Figure 3 (a) Input image to be encrypted: gray-level image


(b) Random key bit stream
(c) Binary image
(d) Binary key-bit
(e) Encrypted image: Binary image XOR Binary key-bit
(f) Decrypted binary image
(g) Decrypted gray-level image

(a)

8
(b)

(c)

(d)

Figure 4 (a) The original image

9
(b) The key bit stream arrays
(c) The binary image
(d) The decrypted gray-level image

6 Model Design

Figure 5 shows the proposed optical encryption system. The proposed system used
two LCDs that represent the key bit stream and the binary digital of the input
gray-level image. The optical encryption system performs the optical XOR
operation, as shown in Fig. 1. It is composed of LCD1, LCD2, two polarizers (P1
and P2), and two CCDs (CCD1 and CCD2), which are main assembly. The gray-
level image is converted to binary bits, which are represented on LCD1. The key
bit stream, which was given by random, represented on LCD2. The optical XOR
operations between the key bit stream and the binary image are performed by
polarization encoding method, as shown in Fig. 1. The results of XOR operations
are detected by the CCD2 camera. This encrypted image can be sent over wireless
or Internet LAN. For the optical decryption of the encrypted image, the encrypted
image should be represented on LCD1. The optical XOR operations between the
key bit stream used in the encryption process and the binary digital of encrypted
image are performed and the results of the optical XOR operations are detected by
CCD2.

Figure 5 Optical Encryption based on XOR model

7 Conclusion

This new optical encryption method that conceals the data of authorized persons
by encryption before they are stored, transmitted or compared in the pattern
recognition system for security system. The original image is encrypted by
performing optical XOR operations with the key bit stream using lenslet arrays
and LCD. The resultant encrypted image, which is detected by a CCD camera, is
converted to an encrypted gray-level image and compares with reference images.
In this security system, each image of authorized persons as a reference image is

10
stored in a memory unit through the proposed encryption system. If an image is
used as an input in the security system for access to a restricted area, it is
encrypted by the proposed encryption method and then compared with the
encrypted reference image. Therefore, when this system is used, it will be difficult
to know the images used in the security system if one does not know the
encryption key bit stream. We verified the idea proposed here with computer
simulations and the simulation results were shown. This proposed system can be
applicable to secure entry systems that identify individuals for access to a
restricted area.

References

Javidi B. and Horner J. L. (1994), “Optical pattern recognition for validation and
security verification,” Opt. Eng. 33(6), 1752-1756.

Frank Stajano (1998), “Visual Cryptography Kit,” University of Cambridge.

Khan A. and Nejib U. (1987), \Optical logic gates employing liquid crystal optical
swithces," Opt. Eng. 26(2), 270-273.

Han J-W., Park C-S., Ryu D-H., and Kim E-S. (1999), \Optical image encryption
based on XOR operations," Opt. Eng. 38(1), 47-54.

Yu F. T. S., Jutamulia, and Gregory D. A. (1987), “Real-time liquid TV XOR-


and XNOR-gate binary image subtraction technique,” Appl. Opt. 26(14), 2738-
2742.

11

You might also like