Image Encryption in QR Codes

By Aniya Pandey

What is Encryption and why it is needed?

For a long time, secure data transmission has been a big problem for organizations and governments. It can be some secrets involving trades or some government mission critical data. Ciphers has been used since historical times for different purposes. Shift ciphers which were not so difficult did took time to break then.


Caesar Cipher used in times of Julius Caesar

Later in the age of computing, ciphers were started being used with software. And which gave rise to new challenges like protecting these against brute force attacks and other vulnerabilities. Key lengths were varied and Data Encryption Standards (DES) was set up . All the ciphers which are present today can encrypt all kinds of data available.

Image Encryption (Method followed):


Two matrices c0 and c1, that would be of dimensions [n x m] where n is total number of shares. Now this is based on the Moni Naor and Adi Shamir’s visual cryptography scheme. According to their theory first the image is divided into shares to follow encryption and to get that image back, we need to recombine the shares. And since we are talking at digital level, we will talk about pixels. Encryption is done in following manner in pixels of an image:

So, we have a source image:


And while going through the encryption process it goes as follows:

So, if we recombine the shares, we will get an image that would be blurred and 4 times larger than the actual image which is one of the problems if we follow this method.


This loss in contrast happens because of the translation of pixels during encryption process because of which black pixels remain same but white pixels turn gray.

Algorithm followed (Flowchart):

Python script was written and the algorithm according to this flowchart was followed.


Problems with using the above method:

It was clearly visible, in the examples above that the output that came out was blurred and 4 times the actual image which is not we want. We always want that we should at least get 99% of the original image back.
Though in case of the example shown above, the image we got is almost 90% clear and things are quite clearly visible. But if take an image where we have TEXT in pictorial form and that is some kind of message that we want to encrypt. This is what will happen to that image as shown below:


We can see that clearly, that the Visibility has gone down, and it is not easy to read the message.

And another drawback of storing texts in images is that, there is always limit to the size of information that we can store in our images. Like we cannot increase the size of image, as the image has a fixed size. Like if there are thousands of lines that we have thousands of lines that we want share in secure way in pictorial form, but image is not capable of storing that. So there is better method in which using large information is possible and that is use of Q-R Codes.

 Q-R Codes:

QR-Codes (Quick Response Codes) are the combination of black squares arranged in white background. QR- Code came out as the result of trademark of Bar-code. QR-Codes can be read and scanned by any imaging devices like scanner and camera or mobile-phone camera or the QR-code laser scanner. Required information is extracted from the pattern and which are there in horizontal and vertical constituents of the images.

Codewords are 8 bits long and use the Reed-Solomon error correction algorithm with four error correction levels. The higher the error correction level, the less storage capacity. The following table lists the approximate error correction capability at each of the four levels:

  1. Level L (Low) 7
  2. Level M (Medium) 15
  3. Level Q (Quartile) 25
  4. Level H (High) 30

Example of Q-R Code:


Now for solving the problem we were having with image encryption that was of contrast loss, we can store our data in Q-R Codes and if we encrypt our Q-R Codes and after recombining the shares what we get back, would be blur image, but that image can be scanned and we can get the information. And I considered low error corrections in this code of all the other options.

So the in the example below we have a Q-R Code which contains a google link:


After going through encryption process and decryption we would again get a 4 times larger image and bit blurred. But the difference here is that even after the image is blurred, the code can be scanned and we can get the desired output.

This is the Q-R Code we get after complete encryption decryption process which is 4 times larger and blurred.


And after scanning the image using a mobile phone camera, we can see below that we get the desired result. So there is no loss of data in this case as the even the blurr Q-R Codes can be scanned and so our purpose of encrypting the image and getting the exact information we desire is achieved.                  


Scanning Q-R Code


Google link found.

Now if we have large amount of data, like many lines of texts and we want to store that in pictorial form, we can store that in Q-R Codes easily and encrypt the Q-R Code. And after decryption we can scan that Q-R Code which would blurred but can be scanned like the case above. Example shown below :

This Q-R Code consists of multiple lines of code.

After encryption and decryption process we will get the following result:


Now this Q-R was scanner and result came out as follows:


Code Scanned


Multiple Lines texts as result


So after going through the entire process, following conclusions were drwan:

  1. Image encryption is based on Moni Naor and Adi Shamir’s research.
  2. For normal images after following whole encryptio and decryption process the image gets 4 times larger and blurred.
  3. Image gets blurred because of translation of pixels.
  4. So Q-R Codes are better to use.
  5. Q-R Codes can store large amount of data.
  6. And even if the Q-R Codes gets blurred and size increases, it can be scanned to reterive the secure information



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s