Visual cryptography
From Wikipedia, the free encyclopedia
Visual cryptography is a cryptographic technique which allows visual information (pictures, text, etc.) to be encrypted in such a way that the decryption can be performed by humans (without computers).
The first visual cryptographic technique was pioneered by Moni Naor and Adi Shamir in 1994. It involved breaking up the image into n shares so that only someone with all n shares could decrypt the image by overlaying each of the shares over each other. Practically, this can be done by printing each share on a separate transparency and then placing all of the transparencies on top of each other. In their technique n-1 shares revealed no information about the original image.
Contents |
[edit] Example
An example of visual cryptography is as follows. Suppose we have an image built up from black and white pixels. We are going to construct two transparencies in such a way that superimposing them (placing them on top of each other) would make the image appear but neither of transparencies individually would provide any information about it. We separate each pixel into two horizontally adjacent ones and fill one of them with black, leaving the other one transparent (on each transparency). If the original had a black pixel, the patterns on the two transparencies will be different, so one of them will be BT and the other TB (T=transparent, B=black). If there was a white pixel, the patterns will be identical, that is, both BT or both TB. One of the transparencies can be filled randomly and the other one accordingly. By placing the two transparencies on top of each other, BT+TB=BB, TB+BT=BB, BT+BT=BT, TB+TB=TB. Therefore, where the original pixel was white, we get a half-black box, and where it was black, we get a completely black one. If viewed from sufficient distance, the former looks grey and the latter looks black, showing the image.
To the right are two images separated using the scheme outlined above. The transparent color is shown by white.
[edit] MATLAB code to display the secret image
img1 = imread( 'Visual-cryptography-1.png', 'png' ); img2 = imread( 'Visual-cryptography-2.png', 'png' ); img3 = 255 - (img1 + img2); imshow( img3 );
[edit] Python code to display the secret image
# Note: This may not be the most elegant way to use Python to decrypt the image. # However, Python is FLOSS, so anyone can use this script. from PIL import Image i1 = Image.open("180px-Visual-cryptography-1.png") i2 = Image.open("180px-Visual-cryptography-2.png") # should be the same size as the first width,height = i1.size w2,h2 = i2.size assert w2 == width assert h2 == height for y in range(0,height): for x in range(0,width): r1,g1,b1 = i1.getpixel((x,y)) r2,g2,b2 = i2.getpixel((x,y)) new_r, new_g, new_b = (255 - r1 + r2, 255 - g1 + g2, 255 - b1 + b2) i1.putpixel((x,y),(new_r,new_g,new_b)) i1.save("decrypted_file.png", "PNG")
[edit] References
- Moni Naor and Adi Shamir, Visual Cryptography, EUROCRYPT 1994, pp1–12 [1].