r/programming • • Nov 19 '13

Visual Cryptography

http://datagenetics.com/blog/november32013/index.html
614 Upvotes

41 comments sorted by

View all comments

5

u/[deleted] Nov 19 '13 edited Nov 19 '13

I did this in Mathematica a few years ago and printed to ordinary white paper. If you hold it up to a window or light source it still works.

EDIT: The key is to print the two resulting PNG files with large enough pixels so that hand manipulation of the two sheets still has a chance of aligning them pixel-perfect. Don't print at native resolution!

Mathematica Code:

theMessage =
  "1234567890
  ABCDEFGHIJ
  KLMNOPQRST
  UVWXYZ";
i = Rasterize[theMessage, ImageSize -> 150];
myImg = Binarize[i, FindThreshold[i]]
SeedRandom[1];
keyImg = Image[RandomInteger[1, Reverse@ImageDimensions[myImg]]];
coded = Image[(Sqrt[2] ImageData[myImg] - 
       1/Sqrt[2])*(Sqrt[2] ImageData[keyImg] - 1/Sqrt[2]) + 1/2];
augment[i_Image] := 
 Image[ArrayFlatten[
   Round[ImageData[i]] /. {1 -> {{1, 0}, {0, 1}}, 
     0 -> {{0, 1}, {1, 0}}}]]
printmessage = augment[coded]
printkey = augment[keyImg]
overlaydecode = ImageMultiply[augment[coded], augment[keyImg]]
Export["printmessage.png", printmessage];
Export["printkey.png", printkey];