Пример #1
0
        internal static string GetHiddenValue(StegoBitmap bitmap, Channel channel)
        {
            byte[] hidden = bitmap.GetChannel(channel);

            bool[] headerBits = hidden.Take(16).SelectMany(x => GetNLastBit(x, 1)).ToArray();
            byte   E          = BoolArrayToByte(headerBits.Take(8).ToArray());
            byte   lengthSize = BoolArrayToByte(headerBits.Skip(8).Take(8).ToArray());

            bool[]      lengthBits  = hidden.Skip(16).Take(lengthSize * 8).SelectMany(x => GetNLastBit(x, 1)).ToArray();
            List <byte> lengthBytes = new List <byte>();

            for (int i = 0; i < lengthBits.Length; i += 8)
            {
                lengthBytes.Add(BoolArrayToByte(lengthBits.Skip(i).Take(8).ToArray()));
            }
            int length = GetIntFromBytes(lengthBytes);

            bool[]      bits  = hidden.Skip(16 + lengthSize * 8).Take(length * 8).SelectMany(x => GetNLastBit(x, 1)).ToArray();
            List <byte> bytes = new List <byte>();

            for (int i = 0; i < bits.Length; i += 8)
            {
                bytes.Add(BoolArrayToByte(bits.Skip(i).Take(8).ToArray()));
            }
            return(ByteArrayToString(bytes.ToArray()));
        }
Пример #2
0
        public StegoBitmap(StegoBitmap stegoBitmap, byte[] changedChannel, Channel channel)
        {
            RedChannel   = stegoBitmap.RedChannel;
            GreenChannel = stegoBitmap.GreenChannel;
            BlueChannel  = stegoBitmap.BlueChannel;

            if (channel == Channel.R)
            {
                RedChannel = changedChannel;
            }
            if (channel == Channel.G)
            {
                GreenChannel = changedChannel;
            }
            if (channel == Channel.B)
            {
                BlueChannel = changedChannel;
            }

            sourceFile = new Bitmap(stegoBitmap.sourceFile.Width, stegoBitmap.sourceFile.Height);

            int counter = 0;

            for (int i = 0; i < sourceFile.Width; i++)
            {
                for (int j = 0; j < sourceFile.Height; j++)
                {
                    sourceFile.SetPixel(i, j, System.Drawing.Color.FromArgb(RedChannel[counter], GreenChannel[counter], BlueChannel[counter]));
                    counter++;
                }
            }
        }
Пример #3
0
        private void DrawHistogram(StegoBitmap sourceBitmap, StegoBitmap modifiedBitmap)
        {
            DrawToCanvas(imgRS, sourceBitmap.RedChannel, System.Windows.Media.Colors.PaleVioletRed);
            DrawToCanvas(imgRM, modifiedBitmap.RedChannel, System.Windows.Media.Colors.DarkRed);

            DrawToCanvas(imgGS, sourceBitmap.GreenChannel, System.Windows.Media.Colors.LightGreen);
            DrawToCanvas(imgGM, modifiedBitmap.GreenChannel, System.Windows.Media.Colors.DarkGreen);

            DrawToCanvas(imgBS, sourceBitmap.BlueChannel, System.Windows.Media.Colors.LightBlue);
            DrawToCanvas(imgBM, modifiedBitmap.BlueChannel, System.Windows.Media.Colors.DarkBlue);
        }
Пример #4
0
        private void Ofd_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
            sourceBitmap     = new StegoBitmap(ofd.FileName);
            imgSource.Source = GetSource(sourceBitmap.GetImage());
            Channel?result = Stego.HasHiddenValue(sourceBitmap);

            if (result.HasValue)
            {
                tbInput.Text = Stego.GetHiddenValue(sourceBitmap, result.Value);
            }
            else
            {
                CalculateLabels();
            }
        }
Пример #5
0
 internal static Channel?HasHiddenValue(StegoBitmap bitmapImage)
 {
     if (HasE(bitmapImage.RedChannel))
     {
         return(Channel.R);
     }
     else if (HasE(bitmapImage.GreenChannel))
     {
         return(Channel.G);
     }
     else if (HasE(bitmapImage.BlueChannel))
     {
         return(Channel.B);
     }
     else
     {
         return(null);
     }
 }
Пример #6
0
        internal static Bitmap Hide(StegoBitmap bitmap, string text, Channel channel)
        {
            byte[] sourceChannel = bitmap.GetChannel(channel);
            byte   flag          = Convert.ToByte('E');
            byte   size          = GetSizeOfLength(text.Length);

            byte[] length    = GetLengthInBytes(text.Length, size);
            byte[] stegoText = StringToByteArray(text);

            byte[] stegoBytes = new byte[1 + 1 + length.Length + stegoText.Length];
            stegoBytes[0] = flag;
            stegoBytes[1] = size;
            int counter = 0;

            for (int i = 0; i < length.Length; i++)
            {
                stegoBytes[i + 2] = length[counter++];
            }
            counter = 0;
            for (int i = 0; i < stegoText.Length; i++)
            {
                stegoBytes[i + 2 + length.Length] = stegoText[counter++];
            }

            bool[] stegoBits = stegoBytes.SelectMany(x => ByteToBoolArray(x)).ToArray();

            for (int i = 0; i < stegoBits.Length; i++)
            {
                if ((sourceChannel[i] % 2 == 0) && stegoBits[i])
                {
                    sourceChannel[i]++;
                }
                else if ((sourceChannel[i] % 2 == 1) && !stegoBits[i])
                {
                    sourceChannel[i]--;
                }
            }
            return(new StegoBitmap(bitmap, sourceChannel, channel).GetImage());
        }
Пример #7
0
        private void BtnHide_Click(object sender, RoutedEventArgs e)
        {
            Channel channel;

            if (((ComboBoxItem)cmbChannel.SelectedItem).Content.ToString() == "Otomatik")
            {
                int changeInRed   = Stego.CalculateChange(sourceBitmap.RedChannel, Stego.StringToByteArray(tbInput.Text));
                int changeInGreen = Stego.CalculateChange(sourceBitmap.GreenChannel, Stego.StringToByteArray(tbInput.Text));
                int changeInBlue  = Stego.CalculateChange(sourceBitmap.BlueChannel, Stego.StringToByteArray(tbInput.Text));
                int min           = changeInRed;
                if (changeInGreen < min)
                {
                    min = changeInGreen;
                }
                if (changeInBlue < min)
                {
                    min = changeInBlue;
                }
                if (min == changeInRed)
                {
                    channel = Channel.R;
                }
                else if (min == changeInGreen)
                {
                    channel = Channel.G;
                }
                else
                {
                    channel = Channel.B;
                }
            }
            else
            {
                channel = (Channel)(cmbChannel.SelectedIndex - 1);
            }
            modifiedBitmap     = new StegoBitmap(Stego.Hide(sourceBitmap, tbInput.Text, channel));
            imgModified.Source = GetSource(modifiedBitmap.GetImage());
            DrawHistogram(sourceBitmap, modifiedBitmap);
        }