Ejemplo n.º 1
0
        public void Extract_message_from_stego_image()
        {
            string path = Path.Combine(basePath, "hided.jpg");
            using (var stream = new StreamReader(path))
            {
                var reader = new JpegImageIO();
                var bytes = reader.ReadRGBFromImage(stream.BaseStream);
                //TestHelper.PrintMatrix("Stego img", bytes);

                var matrix = YCrCb.Parse(bytes);
                //TestHelper.PrintMatrix("Luminance Coeff", matrix);

                var dct = new DCT();
                //dct.Subsample(matrix);
                dct.CalculateDCT(matrix);
                //TestHelper.PrintMatrix("DCT", matrix);

                new Quantizer().ApplyQuantization(matrix, qf);
               // TestHelper.PrintMatrix("QDCT", matrix);

                var stego = new Steganography();
                var message = stego.ExtractMessage(matrix);

                Console.WriteLine(message);
            }
        }
        public void EmbedData(string path, byte[] message)
        {
            using (var stream = new StreamReader(path))
               {
               var imageIo = new JpegImageIO();
               var bytesRGB = imageIo.ReadRGBFromImage(stream.BaseStream);

               var matrix = YCrCb.Parse(bytesRGB);

               var dct = new DCT();
               dct.CalculateDCT(matrix);

               Quantizer q = new Quantizer();

               q.ApplyQuantization(matrix, Qf);

               var stego = new Steganography();
               stego.HideMessage(matrix, message);

               q.ApplyInverseQuantization(matrix, Qf);

               dct.CalculateIDCT(matrix);

               string pathToSave = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "_stego.jpg");

               imageIo.WriteRGBToImage(pathToSave, RGB.Parse(matrix));
               }
        }
        public byte[] ExtractData(string path)
        {
            using (var stream = new StreamReader(path))
               {
               var reader = new JpegImageIO();
               var bytes = reader.ReadRGBFromImage(stream.BaseStream);

               var matrix = YCrCb.Parse(bytes);

               var dct = new DCT();
               dct.CalculateDCT(matrix);

               new Quantizer().ApplyQuantization(matrix, Qf);

               var stego = new Steganography();

               return stego.ExtractMessage(matrix);
               }
        }