I've written some code, it's just an experiment. I had an idea (probably has been done before) to create a random image and set pixels rgb values at random locations to an ascii character number in order to hide messages in the image. It almost works, but for some reason i get strange returns on the decryption such as "tiis is me secter text" instead of "this is my secret text" Well here is the code:
public Form1()
{
InitializeComponent();
}
//storing pixel locations
public static List<int> pixel_list = new List<int>();
public static Bitmap bitmap = new Bitmap(144, 119);
private void Form1_Load(object sender, EventArgs e)
{
bitmap = GenerateNoise(144, 119);
bitmap = encrypt("this is my secret text",bitmap);
pictureBox1.Image = bitmap;
}
public static void decrypt(Bitmap img)
{
string str="";
foreach (int pix in pixel_list)
{
//get the pixel from the list of pixel locations
Color color = img.GetPixel(pix, pix);
//convert the pixels rgb value in to a char and append it to str
str += Convert.ToChar(color.R).ToString();
}
//we have the original message
MessageBox.Show(str);
}
public Bitmap encrypt(string message, Bitmap img)
{
Random rnd = new Random();
byte[] ASCIIValues = Encoding.ASCII.GetBytes(message);
foreach (byte b in ASCIIValues)
{
//select a random pixel
int pixelXY = rnd.Next(1, 119);
//add it to the list
pixel_list.Add(pixelXY);
//chnage that pixels rgb value to the ascii code (b)
img.SetPixel(pixelXY, pixelXY, Color.FromArgb(b, b, b));
}
return img;
}
public Bitmap GenerateNoise(int width, int height)
{
Bitmap finalBmp = new Bitmap(width, height);
Random r = new Random();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
int num = r.Next(0, 256);
finalBmp.SetPixel(x, y, Color.FromArgb(10, num, num, num));
}
}
return finalBmp;
}
private void button1_Click(object sender, EventArgs e)
{
decrypt(bitmap);
}