Example #1
0
        /// <summary>
        /// Embed content
        /// </summary>
        /// <param name="sender">caused the event</param>
        /// <param name="e">event params</param>
        private void embedButton_Click(object sender, EventArgs e)
        {
            // var init
            Boolean success = false;

            // show an error if nothing to embed
            if (this.destFile.Text.Trim() == String.Empty)
            {
                MessageBox.Show("You must supply a destination file in which to embed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ((ContentType)Enum.Parse(typeof(ContentType), this.embedContentType.SelectedItem.ToString()) == ContentType.Text)
            {
                if (this.embedText.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("You must supply text to embed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    EmbeddingContent content  = new EmbeddingContent(this.embedText.Text);
                    EmbeddingPlane   planes   = (EmbeddingPlane)Enum.Parse(typeof(EmbeddingPlane), this.embedPlane.SelectedItem.ToString());
                    byte             bitDepth = Convert.ToByte(this.embedBitDepth.SelectedItem.ToString());
                    using (Bitmap img = SteganographyMethods.Embed(this.sourceFile.Text.Trim(), planes, bitDepth, content))
                    {
                        ImageFormat format = (this.destFileType.SelectedItem.ToString() == "Bmp") ? ImageFormat.Bmp : ImageFormat.Png;
                        success = MainWindow.SaveImgToFile(img, this.destFile.Text.Trim(), format);
                    }
                }
            }
            else if ((ContentType)Enum.Parse(typeof(ContentType), this.embedContentType.SelectedItem.ToString()) == ContentType.File)
            {
                if (this.embedFile.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("You must supply a file to embed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    EmbeddingContent content  = new EmbeddingContent(new FileInfo(this.embedFile.Text.Trim()));
                    EmbeddingPlane   planes   = (EmbeddingPlane)Enum.Parse(typeof(EmbeddingPlane), this.embedPlane.SelectedItem.ToString());
                    byte             bitDepth = Convert.ToByte(this.embedBitDepth.SelectedItem.ToString());
                    using (Bitmap img = SteganographyMethods.Embed(this.sourceFile.Text.Trim(), planes, bitDepth, content))
                    {
                        ImageFormat format = (this.destFileType.SelectedItem.ToString() == "Bmp") ? ImageFormat.Bmp : ImageFormat.Png;
                        success = MainWindow.SaveImgToFile(img, this.destFile.Text.Trim(), format);
                    }
                }
            }

            // notify if the operation is successful
            if (success == true)
            {
                MessageBox.Show("The operation was completed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
 /// <summary>
 /// Updates the bytes available on the embed tab
 /// </summary>
 private void UpdateBytesAvailable()
 {
     // try to figure out how many bytes are available in the file
     try
     {
         using (Bitmap img = new Bitmap(this.sourceFile.Text))
         {
             int            bitDepth = Convert.ToInt32(this.embedBitDepth.SelectedItem.ToString());
             EmbeddingPlane planes   = (EmbeddingPlane)Enum.Parse(typeof(EmbeddingPlane), this.embedPlane.SelectedItem.ToString());
             this.bytesInPicture.Text = SteganographyMethods.MaxBytesInImage(img, planes, bitDepth).ToString();
         }
     }
     catch
     {
         this.bytesInPicture.Text = "N/A";
     }
 }
        public void TestBitOperations()
        {
            // var init
            byte b = 0;

            // bad bit set parameter tests
            b = SteganographyMethods.SetBitValueInByte(byte.MaxValue, 9, 1);
            Assert.AreEqual(b, 0);
            b = SteganographyMethods.SetBitValueInByte(byte.MaxValue, 0, 1);
            Assert.AreEqual(b, 0);
            b = SteganographyMethods.SetBitValueInByte(byte.MaxValue, 1, 2);
            Assert.AreEqual(b, 0);

            // good bit set tests
            b = SteganographyMethods.SetBitValueInByte(byte.MaxValue, 1, 0);
            Assert.AreEqual(b, byte.MaxValue - 1);
            b = SteganographyMethods.SetBitValueInByte(0, 1, 1);
            Assert.AreEqual(b, 1);
            b = SteganographyMethods.SetBitValueInByte(0, 8, 1);
            Assert.AreEqual(b, Math.Pow(2.0, 7.0));
            b = SteganographyMethods.SetBitValueInByte(b, 8, 0);
            Assert.AreEqual(b, 0);

            // bad bit get tests
            b = SteganographyMethods.GetBitValueFromByte(byte.MaxValue, 9);
            Assert.AreEqual(b, 0);
            b = SteganographyMethods.GetBitValueFromByte(byte.MaxValue, 0);
            Assert.AreEqual(b, 0);

            // good bit get tests
            b = SteganographyMethods.GetBitValueFromByte(byte.MaxValue, 8);
            Assert.AreEqual(b, 1);
            b = SteganographyMethods.GetBitValueFromByte(byte.MaxValue, 1);
            Assert.AreEqual(b, 1);

            // good combo tests
            b = SteganographyMethods.SetBitValueInByte(byte.MaxValue, 2, 0);
            Assert.AreEqual(b, byte.MaxValue - 2);
            Assert.AreEqual(SteganographyMethods.GetBitValueFromByte(b, 8), 1);
            Assert.AreEqual(SteganographyMethods.GetBitValueFromByte(b, 1), 1);
            Assert.AreEqual(SteganographyMethods.GetBitValueFromByte(b, 2), 0);
        }
        public void TestBMPTextEmbedDepth2RGBtoBMPandPNG()
        {
            // build content
            const String     TEST_MESSAGE = "this is a test message to check to make sure it works!";
            EmbeddingContent ec           = new EmbeddingContent(TEST_MESSAGE);
            EmbeddingContent recovered    = null;

            // embed
            using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.RGB, 2, ec))
            {
                Assert.IsNotNull(img);
                using (Bitmap png = new Bitmap(img))
                {
                    png.Save("testout.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                    png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png);
                }
            }

            // extract bmp
            recovered = SteganographyMethods.Extract("testout.bmp", EmbeddingPlane.RGB, 2);

            // test
            Assert.IsNotNull(recovered);
            String recoveredMessage = Encoding.ASCII.GetString(recovered.Content);

            Assert.AreEqual(recoveredMessage, TEST_MESSAGE);
            Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text);

            // extract png
            recovered = null;
            recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.RGB, 2);

            // test
            Assert.IsNotNull(recovered);
            recoveredMessage = Encoding.ASCII.GetString(recovered.Content);
            Assert.AreEqual(recoveredMessage, TEST_MESSAGE);
            Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text);

            // cleanup
            File.Delete("testout.bmp");
            File.Delete("testout.png");
        }
Example #5
0
        /// <summary>
        /// Extract content
        /// </summary>
        /// <param name="sender">caused the event</param>
        /// <param name="e">event params</param>
        private void extractButton_Click(object sender, EventArgs e)
        {
            // clear the extracted text box
            this.extractedText.Text = String.Empty;

            // extract!
            EmbeddingPlane   planes   = (EmbeddingPlane)Enum.Parse(typeof(EmbeddingPlane), this.extractPlane.SelectedItem.ToString());
            byte             bitDepth = Convert.ToByte(this.extractBitDepth.SelectedItem.ToString());
            EmbeddingContent content  = SteganographyMethods.Extract(this.sourceFile.Text.Trim(), planes, bitDepth);

            if (content == null)
            {
                // nothing was extracted, show an error message box
                MessageBox.Show("An error occurred while extracting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (content.Header.TypeOfContent == ContentType.Text)
                {
                    // text was extracted, put in extracted text box
                    this.extractedText.Text = Encoding.ASCII.GetString(content.Content);
                }
                else
                {
                    // write to file
                    String newFilename        = String.Format("extracted_{0}", content.Header.Filename);
                    String newPathAndFilename = Path.Combine(Path.GetDirectoryName(this.sourceFile.Text), newFilename);
                    File.WriteAllBytes(newPathAndFilename, content.Content);

                    // extraction mesage
                    String extractionMessage = String.Format("Successfully extracted file: {0}", newFilename);

                    // notify that a file was extracted
                    this.extractedText.Text = extractionMessage;
                    MessageBox.Show(extractionMessage, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        public void TestPNGRandGandBDepth1()
        {
            // build content
            const String     TEST_MESSAGE = "this is a test message to check to make sure it works!";
            EmbeddingContent ec           = new EmbeddingContent(TEST_MESSAGE);
            EmbeddingContent recovered    = null;

            // embed R
            using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.R, 1, ec))
            {
                Assert.IsNotNull(img);
                using (Bitmap png = new Bitmap(img))
                {
                    png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png);
                }
            }

            // extract R
            recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.R, 1);
            Assert.IsNotNull(recovered);

            // test R
            String recoveredMessage = Encoding.ASCII.GetString(recovered.Content);

            Assert.AreEqual(recoveredMessage, TEST_MESSAGE);
            Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text);

            // cleanup R
            recovered = null;
            File.Delete("testout.png");

            // embed G
            using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.G, 1, ec))
            {
                Assert.IsNotNull(img);
                using (Bitmap png = new Bitmap(img))
                {
                    png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png);
                }
            }

            // extract G
            recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.G, 1);
            Assert.IsNotNull(recovered);

            // test G
            recoveredMessage = Encoding.ASCII.GetString(recovered.Content);
            Assert.AreEqual(recoveredMessage, TEST_MESSAGE);
            Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text);

            // cleanup G
            recovered = null;
            File.Delete("testout.png");

            // embed B
            using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.B, 1, ec))
            {
                Assert.IsNotNull(img);
                using (Bitmap png = new Bitmap(img))
                {
                    png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png);
                }
            }

            // extract B
            recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.B, 1);
            Assert.IsNotNull(recovered);

            // test B
            recoveredMessage = Encoding.ASCII.GetString(recovered.Content);
            Assert.AreEqual(recoveredMessage, TEST_MESSAGE);
            Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text);

            // test wrong extraction from G is null (should be B)
            using (Bitmap img = new Bitmap("testout.png"))
            {
                recovered = SteganographyMethods.Extract(img, EmbeddingPlane.G, 2);
            }
            Assert.IsNull(recovered);

            // cleanup B
            File.Delete("testout.png");
        }
        public void TestBMPFileEmbedDepth2RGBtoBMPandPNG()
        {
            // var init
            EmbeddingContent ec        = new EmbeddingContent(new FileInfo("embedfile.jpg"));
            EmbeddingContent recovered = null;
            int height;
            int width;

            // get info aboud the embed file
            using (Bitmap embedfile = new Bitmap("embedfile.jpg"))
            {
                height = embedfile.Height;
                width  = embedfile.Width;
            }

            // embed
            using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.RGB, 2, ec))
            {
                Assert.IsNotNull(img);
                using (Bitmap png = new Bitmap(img))
                {
                    png.Save("testout.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                    png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png);
                }
            }

            // extract file from BMP, get info
            recovered = SteganographyMethods.Extract("testout.bmp", EmbeddingPlane.RGB, 2);
            Assert.IsNotNull(recovered);
            File.WriteAllBytes("recovered.jpg", recovered.Content);

            // test
            Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.File);
            Assert.AreEqual(recovered.Content.Length, (new FileInfo("recovered.jpg")).Length);
            using (Bitmap embedfile = new Bitmap("recovered.jpg"))
            {
                Assert.AreEqual(height, embedfile.Height);
                Assert.AreEqual(width, embedfile.Width);
            }

            // cleanup
            recovered = null;
            File.Delete("recovered.jpg");

            // extract from PNG
            recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.RGB, 2);
            Assert.IsNotNull(recovered);
            File.WriteAllBytes("recovered.jpg", recovered.Content);

            // test
            Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.File);
            Assert.AreEqual(recovered.Content.Length, (new FileInfo("recovered.jpg")).Length);
            using (Bitmap embedfile = new Bitmap("recovered.jpg"))
            {
                Assert.AreEqual(height, embedfile.Height);
                Assert.AreEqual(width, embedfile.Width);
            }

            // cleanup
            File.Delete("recovered.jpg");
            File.Delete("testout.bmp");
            File.Delete("testout.png");
        }