After combining two images
Merry Christmas! Before writing this article, I wrote an article about Visual cryptography. But it's in text base, that means when you enter text and it will generate a visual encrypted images for you.
Recently, I received an email for if it can do in image base, select image and return encrypted images. And answer is of cause.
Visual cryptography was introduced by Naor and Shamir at EUROCRYPT '94. They asked the following intriguing question: is it possible to devise a secret sharing scheme in which an image can be reconstructed "visually" by superimposing two shares? Each share would consist of a transparency, made up of black and white pixels. (Note that it would be more accurate to say "transparent" rather than "white".) Examination of one share should reveal no information about the image.
For more details, please read this.
Using the Code
The main difference between Image and Text is that you can control the text background in Black and White but Image contains Color, so first what we need is to convert the color into Black and White:
private Bitmap ConvertToBackAndWhite(Bitmap source)
int sourceWidth = source.Width;
int sourceHeight = source.Height;
Bitmap result = new Bitmap(sourceWidth, sourceHeight);
double mid = 255d * (1d / 2d);
for (int x = 0; x < sourceWidth; x++)
for (int y = 0; y < sourceHeight; y++)
Color c = source.GetPixel(x, y);
c = (Average(c.R, c.G, c.B) > mid) ? Color.Empty : Color.Black;
result.SetPixel(x, y, c);
After converting the image to black and white, the other is the same as text encryption. And I'm not describing the details here.
Enjoy the article and Christmas Holidays.
- 26th December, 2011: Initial post