hello all,
I am working on a project in steganography for my final year.This project is based on hiding text data in image file.
I am using Least Significant Bit algorithm to start with.
I am starting by converting text file as well as image file to byte array and then to bit array.I have been successful
in converting text to bit array.
but problem is with image file. when i convert it to bits , the program just hangs and does not respond(may be because of size
of the image )
I hav pasted the code for both text file as well as image file below.I hav made the image conversion working by
running loop until 512,but i want to read the whole image into bit array.
How can I achieve this? Can there be a better method to do steganography? Should I use multithreading..Please help.
Any advice for code improvement is welcomed.
Thanks in advance.
Code:
private void browsetext_Click(object sender, EventArgs e)
{
try
{
string name = null;
string text=null;
FileStream fs;
StreamReader sr;
OpenFileDialog op1 = new OpenFileDialog();
op1.Filter = "text files(*.txt,*.doc,*.docx)|*.txt;*.doc;*.docx";
if (op1.ShowDialog() == DialogResult.OK)
{
name = op1.FileName;
fs = new FileStream(@name, FileMode.Open, FileAccess.Read);
sr = new StreamReader(fs);
text= sr.ReadToEnd();
textBox1.Text = text;
byte[] b = Encoding.ASCII.GetBytes(text);
for(int i=0;i<b.Length;i++)
{
textBox2.Text+=b[i].ToString()+" ";
}
BitArray b1 = new BitArray(b);
for (int j = 0; j < b1.Length; j++)
{
int k = Convert.ToInt32( b1[j]);
if (j % 8 == 0)
{
textBox3.Text += " ";
}
textBox3.Text += k.ToString();
}
fs.Close();
sr.Close();
}
}
catch (Exception q)
{
MessageBox.Show(q.Message.ToString());
}
}
private void browsePic_Click(object sender, EventArgs e)
{
try
{
//FileStream fs1;
string name1 = null;
string text1 = null;
Image img = null;
FileStream fs1;
StreamReader sr1;
OpenFileDialog op2 = new OpenFileDialog();
op2.Filter = "image files(*.bmp,*.gif,*.jpeg)|*.bmp;*.gif;*.jpg";
if (op2.ShowDialog() == DialogResult.OK)
{
name1 = op2.FileName;
img = Image.FromFile(name1);
//fs1 = new FileStream(name1, FileMode.Open, FileAccess.Read);
pictureBox1.Image = img;
//byte[] im;
//MemoryStream ms = new MemoryStream();
//img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
//im = ms.ToArray();
//for (int i = 0; i < im.Length; i++)
//{
// textBox4.Text += im[i].ToString()+" ";
//}
// BitArray im1 = new BitArray(im);
fs1 = new FileStream(name1, FileMode.Open, FileAccess.Read);
sr1 = new StreamReader(fs1);
text1 = sr1.ReadToEnd();
byte[] im = Encoding.ASCII.GetBytes(text1);
for (int i = 0; i < 512; i++)
{
textBox4.Text += im[i].ToString() + " ";
}
BitArray im1 = new BitArray(im);
for(int j=0;j<512;j++)
{
textBox5.Text += Convert.ToInt32(im1[j]).ToString();
}
}
}
catch (Exception q)
{
MessageBox.Show(q.Message.ToString());
}
}