Example #1
0
 public static string GetDecryptedTextFromImageLinear(Image image)
 {
     Bitmap img = new Bitmap(image);
     int maxLinear = image.Width * image.Height;
     string pass = string.Format("{0}x{1}={2}", image.Width, image.Height, maxLinear);
     AESEncrypt encrypt = new AESEncrypt();
     string text = string.Empty;
     int value = 0;
     int i = 0;
     OutputConsole.Write("Processing image...");
     do
     {
         Point point = LinearIndexToPoint(i, image.Width, image.Height);
         Color pixel = img.GetPixel(point.X, point.Y);
         value = DecodePixel(pixel);
         i++;
         if (value != 255)
             text += Convert.ToChar(value);
     } while (value != 255);
     try
     {
         OutputConsole.Write(string.Format("String found: \n{0}", text));
         OutputConsole.Write("Decrypting text...");
         return encrypt.DecryptString(text, pass);
     }
     catch (Exception e)
     {
         OutputConsole.Write("Error: Text not found");
         Console.WriteLine(e.Message);
         return null;
     }
 }
        private static void EncodeMessageLinear(ref Bitmap img, string text)
        {
            int        maxLinear = img.Width * img.Height;
            string     pass      = string.Format("{0}x{1}={2}", img.Width, img.Height, maxLinear);
            AESEncrypt encrypt   = new AESEncrypt();
            int        c         = 0;
            string     encrypted = encrypt.EncryptString(text, pass);

            OutputConsole.Write(string.Format("Text encrypted \n{0}", encrypted));
            OutputConsole.Write("Processing image...");
            if (encrypted.Length < maxLinear)
            {
                for (int i = 0; i < encrypted.Length; i++)
                {
                    Point point  = LinearIndexToPoint(i, img.Width, img.Height);
                    Color pixel  = img.GetPixel(point.X, point.Y);
                    char  letter = encrypted[i];
                    int   value  = Convert.ToInt32(letter);
                    Color n      = EncodePixel(pixel, value);
                    img.SetPixel(point.X, point.Y, n);
                    c = i;
                }
                //Null value placed at the end to indicate end of text - or using 255 for better hiding
                Point pointEnd = LinearIndexToPoint(c, img.Width, img.Height);
                Color pixelEnd = img.GetPixel(pointEnd.X, pointEnd.Y);
                img.SetPixel(pointEnd.X, pointEnd.Y, EncodePixel(pixelEnd, 0));
                OutputConsole.Write("Finished embedding encrypted text");
            }
            else
            {
                OutputConsole.Write("Error: Image size doesn't support encrypted text size");
                img = null;
            }
        }
        public static string GetDecryptedTextFromImageLinear(Image image)
        {
            Bitmap     img       = new Bitmap(image);
            int        maxLinear = image.Width * image.Height;
            string     pass      = string.Format("{0}x{1}={2}", image.Width, image.Height, maxLinear);
            AESEncrypt encrypt   = new AESEncrypt();
            string     text      = string.Empty;
            int        value     = 0;
            int        i         = 0;

            OutputConsole.Write("Processing image...");
            do
            {
                Point point = LinearIndexToPoint(i, image.Width, image.Height);
                Color pixel = img.GetPixel(point.X, point.Y);
                value = DecodePixel(pixel);
                i++;
                if (value != 255)
                {
                    text += Convert.ToChar(value);
                }
            } while (value != 255);
            try
            {
                OutputConsole.Write(string.Format("String found: \n{0}", text));
                OutputConsole.Write("Decrypting text...");
                return(encrypt.DecryptString(text, pass));
            }
            catch (Exception e)
            {
                OutputConsole.Write("Error: Text not found");
                Console.WriteLine(e.Message);
                return(null);
            }
        }
        public static byte[] EncryptTextLinear(byte[] wav, string text)
        {
            WavAudio   audio     = new WavAudio(wav);
            uint       value     = 0;
            string     pass      = string.Format(audio.bitsPerSample.ToString());
            AESEncrypt encrypt   = new AESEncrypt();
            string     encrypted = encrypt.EncryptString(text, pass);

            OutputConsole.Write(string.Format("Text encrypted \n{0}", encrypted));
            if (encrypted.Length <= Math.Floor((double)(audio.totalSamples / 8)))
            {
                uint n = 0;
                OutputConsole.Write("Seed generated");
                OutputConsole.Write("Processing wav file...");
                for (int i = 0; i < encrypted.Length; i++)
                {
                    value = encrypted[i];
                    for (int x = 0; x < 8; x++)
                    {
                        uint sample      = n;
                        uint sampleValue = audio.samples[sample];
                        sampleValue           = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1);
                        audio.samples[sample] = sampleValue;
                        n++;
                    }
                }
                value = 0;
                for (int x = 0; x < 8; x++)
                {
                    uint sample      = n;
                    uint sampleValue = audio.samples[sample];
                    sampleValue           = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1);
                    audio.samples[sample] = sampleValue;
                    n++;
                }
                audio.Save();
                OutputConsole.Write(string.Format("Text encrypted... used {0} samples", encrypted.Length * 8));
                OutputConsole.Write("Saving wav file");
                return(audio.data);
            }
            else
            {
                return(null);
            }
        }
        public static string DecryptTextLinear(byte[] wav)
        {
            WavAudio   audio   = new WavAudio(wav);
            string     text    = string.Empty;
            uint       n       = 0;
            uint       value   = 0;
            string     pass    = string.Format(audio.bitsPerSample.ToString());
            AESEncrypt encrypt = new AESEncrypt();

            OutputConsole.Write("Processing wav file...");
            do
            {
                value = 0;
                for (int x = 0; x < 8; x++)
                {
                    uint sample      = n;
                    uint sampleValue = audio.samples[sample];
                    value = value | ((sampleValue & 1) << x);
                    n++;
                }
                if (value != 0)
                {
                    text += Convert.ToChar(value);
                }
            } while (value != 0);
            OutputConsole.Write("Decrypting text...");
            try
            {
                return(encrypt.DecryptString(text, pass));
            }
            catch (Exception e)
            {
                OutputConsole.Write("Error: Text not found");
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Example #6
0
 private static void EncodeMessageLinear(ref Bitmap img, string text)
 {
     int maxLinear = img.Width * img.Height;
     string pass = string.Format("{0}x{1}={2}", img.Width, img.Height, maxLinear);
     AESEncrypt encrypt = new AESEncrypt();
     int c = 0;
     string encrypted = encrypt.EncryptString(text, pass);
     OutputConsole.Write(string.Format("Text encrypted \n{0}", encrypted));
     OutputConsole.Write("Processing image...");
     if (encrypted.Length < maxLinear)
     {
         for (int i = 0; i < encrypted.Length; i++)
         {
             Point point = LinearIndexToPoint(i, img.Width, img.Height);
             Color pixel = img.GetPixel(point.X, point.Y);
             char letter = encrypted[i];
             int value = Convert.ToInt32(letter);
             Color n = EncodePixel(pixel, value);
             img.SetPixel(point.X, point.Y, n);
             c = i;
         }
         //Null value placed at the end to indicate end of text - or using 255 for better hiding
         Point pointEnd = LinearIndexToPoint(c, img.Width, img.Height);
         Color pixelEnd = img.GetPixel(pointEnd.X, pointEnd.Y);
         img.SetPixel(pointEnd.X, pointEnd.Y, EncodePixel(pixelEnd, 0));
         OutputConsole.Write("Finished embedding encrypted text");
     }
     else
     {
         OutputConsole.Write("Error: Image size doesn't support encrypted text size");
         img = null;
     }
 }
        public static byte[] EncryptTextLinear(byte[] wav, string text)
        {
            WavAudio audio = new WavAudio(wav);
            uint value = 0;
            string pass = string.Format(audio.bitsPerSample.ToString());
            AESEncrypt encrypt = new AESEncrypt();
            string encrypted = encrypt.EncryptString(text, pass);
            OutputConsole.Write(string.Format("Text encrypted \n{0}", encrypted));
            if (encrypted.Length <= Math.Floor((double)(audio.totalSamples / 8)))
            {
                uint n = 0;
                OutputConsole.Write("Seed generated");
                OutputConsole.Write("Processing wav file...");
                for (int i = 0; i < encrypted.Length; i++)
                {
                    value = encrypted[i];
                    for (int x = 0; x < 8; x++)
                    {
                        uint sample = n;
                        uint sampleValue = audio.samples[sample];
                        sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1);
                        audio.samples[sample] = sampleValue;
                        n++;
                    }

                }
                value = 0;
                for (int x = 0; x < 8; x++)
                {
                    uint sample = n;
                    uint sampleValue = audio.samples[sample];
                    sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1);
                    audio.samples[sample] = sampleValue;
                    n++;
                }
                audio.Save();
                OutputConsole.Write(string.Format("Text encrypted... used {0} samples", encrypted.Length * 8));
                OutputConsole.Write("Saving wav file");
                return audio.data;
            }
            else
            {
                return null;
            }
        }
 public static string DecryptTextLinear(byte[] wav)
 {
     WavAudio audio = new WavAudio(wav);
     string text = string.Empty;
     uint n = 0;
     uint value = 0;
     string pass = string.Format(audio.bitsPerSample.ToString());
     AESEncrypt encrypt = new AESEncrypt();
     OutputConsole.Write("Processing wav file...");
     do
     {
         value = 0;
         for (int x = 0; x < 8; x++)
         {
             uint sample = n;
             uint sampleValue = audio.samples[sample];
             value = value | ((sampleValue & 1) << x);
             n++;
         }
         if (value != 0)
             text += Convert.ToChar(value);
     } while (value != 0);
     OutputConsole.Write("Decrypting text...");
     try
     {
         return encrypt.DecryptString(text, pass);
     }
     catch (Exception e)
     {
         OutputConsole.Write("Error: Text not found");
         Console.WriteLine(e.Message);
         return null;
     }
 }