Example #1
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;
            }
        }
Example #2
0
        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);
            }
        }