Пример #1
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");
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
        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");
        }
Пример #4
0
        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");
        }