13,739,901 members
alternative version

#### Stats

81.9K views
41 bookmarked
Posted 22 Oct 2007
Licenced CPOL

# Visual Cryptography Generator

, 22 Oct 2007
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 the human visual system, without the aid of computers.

## Introduction

I should say "Thank you" to tectures, I write this article because of his idea.

Before writing this article, I've written an article about alpha in PNG to make a magic card for friends and tectures asked me what's the different between my program and Visual cryptography. Actually, in that article I didn't think about encrypting anything inside the image, it just did a simple track and made your friends happy.

And I found that no one had written this before, so I've made a simple program to represent this concept.

## Background

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.

## Using the Code

Two constant variables that need to be defined are as follows:

```private Size IMAGE_SIZE = new Size(437, 106); //Image size
private const int GENERATE_IMAGE_COUNT = 2; //How many images you would like to generate```

The following function generates the shared image:

```private Bitmap[] GenerateImage(string inputText)
{
Bitmap finalImage = new Bitmap(IMAGE_SIZE.Width, IMAGE_SIZE.Height);
Bitmap tempImage = new Bitmap(IMAGE_SIZE.Width / 2, IMAGE_SIZE.Height);
Bitmap[] image = new Bitmap[GENERATE_IMAGE_COUNT];

Random rand = new Random();
SolidBrush brush = new SolidBrush(Color.Black);
Point mid = new Point(IMAGE_SIZE.Width / 2, IMAGE_SIZE.Height / 2);
Graphics g = Graphics.FromImage(finalImage);
Graphics gtemp = Graphics.FromImage(tempImage);

//set text format
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
Font font = new Font("Times New Roman", 48);

Color fontColor;
g.DrawString(inputText, font, brush, mid, sf);
gtemp.DrawImage(finalImage, 0, 0, tempImage.Width, tempImage.Height);
for (int i = 0; i < image.Length; i++)
{
image[i] = new Bitmap(IMAGE_SIZE.Width, IMAGE_SIZE.Height);
}

int index = -1;
int width = tempImage.Width;
int height = tempImage.Height;
for (int x = 0; x < width; x += 1)
{
for (int y = 0; y < height; y += 1)
{
fontColor = tempImage.GetPixel(x, y);
index = rand.Next(image.Length);

//Check if the color empty
if (fontColor.Name == Color.Empty.Name)
{
for (int i = 0; i < image.Length; i++)
{
if (index == 0)
{
image[i].SetPixel(x * 2, y, Color.Black);
image[i].SetPixel(x * 2 + 1, y, Color.Empty);
}
else
{
image[i].SetPixel(x * 2, y, Color.Empty);
image[i].SetPixel(x * 2 + 1, y, Color.Black);
}
}
}
else
{
for (int i = 0; i < image.Length; i++)
{
if ((index + i) % image.Length == 0)
{
image[i].SetPixel(x * 2, y, Color.Black);
image[i].SetPixel(x * 2 + 1, y, Color.Empty);
}
else
{
image[i].SetPixel(x * 2, y, Color.Empty);
image[i].SetPixel(x * 2 + 1, y, Color.Black);
}
}
}
}
}

//Clean Up
brush.Dispose();
tempImage.Dispose();
finalImage.Dispose();

return image;
}```

## Points of Interest

They demonstrated a visual secret sharing scheme, where an image was broken up into n shares so that only someone with all n shares could decrypt the image, while any n-1 shares revealed no information about the original image. Each share was printed on a separate transparency, and decryption was performed by overlaying the shares. When all n shares were overlayed, the original image would appear.

## History

• 23rd October, 2007: Initial post

## Share

 Architect MouxIdea Limited Hong Kong
1981 Born in Hong Kong
1999 The Year Before Millennium
2000 First touch of programming - ASP(guestbook)
2001 Outstanding Student Award - Computing Department
2002 Xcellence Developer Awards - Best Graphical Focused Application(Game) Award
2003 Microsoft MVP - .NET
2004 Be lost in Technology
2005 Microsoft MVP - C#
2006 Microsoft MVP - C#
2007 Getting Marry - Cheers~
2008 Microsoft MVP - C#
2009 Microsoft MVP - C#
2010 Microsoft MVP - C#
2011 Start my software hut

http://www.csharpfans.com

http://www.bugyiu.com

http://www.mouxidea.com

## You may also be interested in...

 First PrevNext
 How to implement it for web forms application? 24-Sep-16 18:37 24-Sep-16 18:37
 Re: How to implement it for web forms application? Jacky Yiu12-Oct-16 21:26 Jacky Yiu 12-Oct-16 21:26
 Re: How to implement it for web forms application? 10-Dec-16 19:13 10-Dec-16 19:13
 Re: How to implement it for web forms application? Jacky Yiu10-Apr-17 22:04 Jacky Yiu 10-Apr-17 22:04
 greetings Lithin Nasani17-Mar-15 19:50 Lithin Nasani 17-Mar-15 19:50
 How to Decryt the Encrypted image Nandhakumar Jothi3-Dec-14 3:17 Nandhakumar Jothi 3-Dec-14 3:17
 Re: How to Decryt the Encrypted image Jacky Yiu23-Apr-15 18:01 Jacky Yiu 23-Apr-15 18:01
 How to decrypt Generating two images Member 1118606930-Nov-14 23:41 Member 11186069 30-Nov-14 23:41
 Re: How to decrypt Generating two images Jacky Yiu23-Apr-15 18:33 Jacky Yiu 23-Apr-15 18:33
 How to download Third Image Member 1118606929-Nov-14 0:30 Member 11186069 29-Nov-14 0:30
 How to get Original image? SOHAM_GANDHI3-Sep-14 20:40 SOHAM_GANDHI 3-Sep-14 20:40
 Re: How to get Original image? Jacky Yiu4-Nov-14 22:58 Jacky Yiu 4-Nov-14 22:58
 Re: How to get Original image? SOHAM_GANDHI4-Nov-14 23:06 SOHAM_GANDHI 4-Nov-14 23:06
 Very Good Article Madam but As am New to C#.Net I am Not Able to Understand it in detailed...so please can you provide any explanation to the code.. santhosh281-Aug-14 0:31 santhosh28 1-Aug-14 0:31
 Visual cryptography Lawrence3628-Dec-13 6:08 Lawrence36 28-Dec-13 6:08
 Re: Visual cryptography Jacky Yiu5-Mar-14 21:33 Jacky Yiu 5-Mar-14 21:33
 Color Cryptography Ideas... manuthebos11-Apr-13 20:27 manuthebos 11-Apr-13 20:27
 request Akbar basha km18-Jan-13 6:04 Akbar basha km 18-Jan-13 6:04
 Re: request 23-Oct-13 15:29 23-Oct-13 15:29
 My vote of 5 Vinamaruthi20-Dec-11 0:19 Vinamaruthi 20-Dec-11 0:19
 I like this. Somehow it got less votes. But it is a good one. My 5 Albin Abel16-Mar-11 19:59 Albin Abel 16-Mar-11 19:59
 Great Idea Bigdeak10-Jun-10 3:01 Bigdeak 10-Jun-10 3:01
 Great Minds think alike... Keith Vinson29-Oct-07 12:09 Keith Vinson 29-Oct-07 12:09
 Re: Great Minds think alike... Jacky Yiu1-Nov-07 17:00 Jacky Yiu 1-Nov-07 17:00
 Last Visit: 31-Dec-99 18:00     Last Update: 23-Oct-18 3:28 Refresh 12 Next »