Beispiel #1
0
        //HIDE

        private void hide_Click(object sender, EventArgs e)
        {
            //SELECT IMAGE TO HIDE TEXT
            MessageBox.Show("Select image to hide text");
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = new Bitmap(openFileDialog.FileName);
                textBox1.Text    += "To hide the text:" + openFileDialog.FileName + Environment.NewLine;
            }

            //SELECT THE TEXT FILE TO HIDE IN IMAGE
            MessageBox.Show("Select text file to hide");
            openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text += "Text file to be embedded in the image:" + openFileDialog.FileName + Environment.NewLine;
                string[] tmp = openFileDialog.FileName.Split('\\');
                textFileName = tmp[tmp.Length - 1];
                if (!string.IsNullOrEmpty(vigenerekey.Text) && checkKey(vigenerekey) == true)
                {
                    Vigenere.encrypt(openFileDialog.FileName, vigenerekey.Text);
                    textfile = File.ReadAllBytes(@"C:\ProgramData\stegpro_encrypted.txt");
                    File.Delete(@"C:\ProgramData\stegpro_encrypted.txt");
                }
                else
                {
                    textfile = File.ReadAllBytes(openFileDialog.FileName);
                }
            }

            //GET IMAGE SIZE AND PIXELS

            Bitmap bmp = new Bitmap(pictureBox1.Image);
            int    x   = bmp.Width;
            int    y   = bmp.Height;

            byte[] r = new byte[x * y];
            byte[] g = new byte[x * y];
            byte[] b = new byte[x * y];
            k = 0;

            for (i = 0; i < y; i++)
            {
                for (j = 0; j < x; j++)
                {
                    r[k] = bmp.GetPixel(j, i).R;
                    g[k] = bmp.GetPixel(j, i).G;
                    b[k] = bmp.GetPixel(j, i).B;
                    k++;
                }
            }

            //CHANGE BITS BETWEEN TEXT FILE BITS AND IMAGE PIXELS LSB BITS
            BitArray textBits = new BitArray(textfile);

            i = 0; j = 0;
            changeBits(r, textBits);
            changeBits(g, textBits);
            changeBits(b, textBits);

            Bitmap newImage = (Bitmap)bmp.Clone();

            x = bmp.Width;
            y = bmp.Height;
            k = 0;
            Color rgb;

            for (i = 0; i < y; i++)
            {
                for (j = 0; j < x; j++)
                {
                    rgb = Color.FromArgb((int)r[k], (int)g[k], (int)b[k]);
                    newImage.SetPixel(j, i, rgb);
                    k++;
                }
            }
            textBox1.Text += "The text file is embedded in the image." + Environment.NewLine;

            //SAVE IMAGE TO CUSTOM FOLDER
            pictureBox2.Image = newImage;
            var savePath = new FolderBrowserDialog();

            MessageBox.Show("Select folder to save the new image");
            if (savePath.ShowDialog() == DialogResult.OK)
            {
                string folderName = savePath.SelectedPath;
                pictureBox2.Image.Save(folderName + "\\newImage.png", ImageFormat.Png);
            }
            textBox1.Text += "The new image is saved to " + savePath.SelectedPath + "\\newImage.png" + Environment.NewLine;
        }
Beispiel #2
0
//EXTRACT
        private void extract_Click(object sender, EventArgs e)
        {
            //SELECT IMAGE TO EXTRACT THE TEXT
            MessageBox.Show("Select image to extract the text");
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                pictureBox2.Image = new Bitmap(openFileDialog.FileName);
                results(textBox1);
                textBox1.Text += "The text will be extract from this image:" + openFileDialog.FileName + Environment.NewLine;
            }

            //GET IMAGE PIXELS
            Bitmap bmp = new Bitmap(pictureBox2.Image);
            int    x   = bmp.Width;
            int    y   = bmp.Height;

            byte[] r = new byte[x * y];
            byte[] g = new byte[x * y];
            byte[] b = new byte[x * y];
            k = 0;

            for (i = 0; i < y; i++)
            {
                for (j = 0; j < x; j++)
                {
                    r[k] = bmp.GetPixel(j, i).R;
                    g[k] = bmp.GetPixel(j, i).G;
                    b[k] = bmp.GetPixel(j, i).B;
                    k++;
                }
            }

            //EXTRACT ALL BITS
            BitArray extractBits = new BitArray(8);

            k = 0;
            l = 0;
            int length = (r.Length + g.Length + b.Length) / 8;

            tmpBytes = new byte[length];

            extractAllBits(r, extractBits);
            extractAllBits(g, extractBits);
            extractAllBits(b, extractBits);


            //BIT ARRAY TO BYTE ARRAY
            byte[] extractBytes = new byte[l];
            for (int i = 0; i < extractBytes.Length; i++)
            {
                extractBytes[i] = tmpBytes[i];
            }

            //VIGENERE DECRYPTION
            if (!string.IsNullOrEmpty(vigenerekey.Text) && checkKey(vigenerekey) == true)
            {
                Vigenere.decrypt(extractBytes, vigenerekey.Text);
            }

            //SAVE TEXT FILE TO CUSTOM FOLDER
            var savePath = new FolderBrowserDialog();

            MessageBox.Show("Select folder to save the extracted text file");
            if (savePath.ShowDialog() == DialogResult.OK)
            {
                string folderName = savePath.SelectedPath;
                File.WriteAllBytes(folderName + "\\extracted_text.txt", extractBytes);
            }
            textBox1.Text += "The extracted file saved to " + savePath.SelectedPath + "\\extracted_text.txt" + Environment.NewLine;
        }