예제 #1
0
        private void buttonEncode_Click(object sender, EventArgs e)
        {
            try
            {
                int key;
                if (!int.TryParse(textBoxGetEncodeKey.Text, out key))
                {
                    throw new Exception("Ошибка при вводе ключа!");
                }

                EncodeKey = Int32.Parse(textBoxGetEncodeKey.Text);

                SteganoTransformation transformation = new SteganoTransformation();
                SteganoContainer      container      = new SteganoContainer(ContainerForEncode);
                SteganoMessage        message        = new SteganoMessage(InputMessage);
                container.InitBlocks(8, 8);
                container.InitBlueComponent(8, 8);
                transformation.Encode(container, message, EncodeKey, 250);
                container.InsertBlueComponent(8, 8);
                container.SaveImage(8, 8, "encode_output.bmp");

                MessageBox.Show("Успешно!\nФайл находится в директории:\n" + Directory.GetCurrentDirectory(), "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception excptn)
            {
                MessageBox.Show("Анта бака!\nОшибка при кодировании!\n" + excptn.Message + excptn.StackTrace, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public double [] getPSNRValues(string original, string message, int maxP, int key)
        {
            double [] PSNRvalues = new double[maxP];

            Parallel.For(0, maxP, ctr => {
                SteganoTransformation transformation = new SteganoTransformation();
                SteganoContainer originalImage       = new SteganoContainer(original);
                SteganoContainer container           = new SteganoContainer(original);
                SteganoMessage originalMessage       = new SteganoMessage(message);
                container.InitBlocks(8, 8);
                container.InitBlueComponent(8, 8);
                transformation.Encode(container, originalMessage, key, ctr);
                container.InsertBlueComponent(8, 8);
                container.SaveBitmap(8, 8);
                double buf      = getPSNR(originalImage, container);
                PSNRvalues[ctr] = buf;
                container.Image.Dispose();
                originalImage.Image.Dispose();
            });

            return(PSNRvalues);
        }
예제 #3
0
        public void Encode(SteganoContainer container, SteganoMessage steganoMessage, int key, int P)
        {
            if (steganoMessage.Size + 32 > container.Blocks.Count)
            {
                throw new Exception("Размер контейнера слишком мал, сэмпай!");
            }

            //Применили дкп ко всем блокам 8х8
            foreach (var block in container.BlueComponent)
            {
                EncodeCoefficient.Add(DKP.Dkp(block));
            }

            Random rnd = new Random(key);

            bool[] data = new bool[container.BlueComponent.Count - 32];

            for (int i = 0; i < steganoMessage.DataBinaryString.Length; i++)
            {
                data[i] = true;
            }

            var distribution         = Shuffle(data, rnd);
            var steganoMessageLength = GetBinaryStringFromUInt32(steganoMessage.Size);

            // put data about message length in blocks
            for (int counter = 0; counter < 32; counter++)
            {
                EncodeCoefficient[counter] = DKP.CoefficientChange(EncodeCoefficient[counter],
                                                                   steganoMessageLength[counter], u1, v1, u2, v2, P);
            }

            int marker = 32;

            for (int i = 32; i < container.BlueComponent.Count; i++)
            {
                if (marker == steganoMessage.DataBinaryString.Length + 32)
                {
                    break;
                }

                if (distribution[i - 32] == true)
                {
                    EncodeCoefficient[i] = DKP.CoefficientChange(EncodeCoefficient[i], steganoMessage.DataBinaryString[marker - 32], u1, v1, u2, v2, P);
                    marker += 1;
                }
                else
                {
                    continue;
                }
            }

            foreach (var block in EncodeCoefficient)
            {
                EncodeCoefficientForWrite.Add(DKP.Odkp(block));
            }

            // change BlueComponent in container
            for (var counter = 0; counter < container.BlueComponent.Count; counter++)
            {
                byte[,] buf = new byte[8, 8];
                for (uint i = 0; i < 8; i++)
                {
                    for (uint k = 0; k < 8; k++)
                    {
                        if (EncodeCoefficientForWrite[counter][i, k] < 0)
                        {
                            buf[i, k] = 0;
                        }
                        else if (EncodeCoefficientForWrite[counter][i, k] > 255)
                        {
                            buf[i, k] = 255;
                        }
                        else
                        {
                            buf[i, k] = (byte)Math.Round(EncodeCoefficientForWrite[counter][i, k]);
                        }
                    }
                }
                container.BlueComponent[counter] = buf;
            }
        }
예제 #4
0
        public void Decode(SteganoContainer container, SteganoMessage steganoMessage, int key)
        {
            // Применили ДКП к блокам 8х8
            foreach (var block in container.BlueComponent)
            {
                DecodeCoefficient.Add(DKP.Dkp(block));
            }

            double Abs1;
            double Abs2;

            string bits = "";  //временная переменная для записи сообщения

            double[,] dkp_8x8; // временная переменная для одной матрицы 8на8

            var steganoMessageLength = "";

            for (int counter = 0; counter < 32; counter++)
            {
                dkp_8x8 = DecodeCoefficient[counter];
                Abs1    = Math.Abs(dkp_8x8[u1, v1]);
                Abs2    = Math.Abs(dkp_8x8[u2, v2]);
                if (Abs1 > Abs2)
                {
                    steganoMessageLength += "0";
                }
                if (Abs1 < Abs2)
                {
                    steganoMessageLength += "1";
                }
            }

            var steganoMessageLengthUInt32 = GetUInt32FromBinaryString(steganoMessageLength);

            if (steganoMessageLengthUInt32 + 32 > container.Blocks.Count)
            {
                throw new Exception("Контейнер поврежден, сэмпай!");
            }

            Random rnd = new Random(key);

            bool[] data = new bool[container.BlueComponent.Count - 32];

            for (int i = 0; i < steganoMessageLengthUInt32; i++)
            {
                data[i] = true;
            }

            var distribution = Shuffle(data, rnd);

            for (int k = 32; k < container.Blocks.Count; k++)
            {
                if (distribution[k - 32] == true)
                {
                    dkp_8x8 = DecodeCoefficient[k];
                    Abs1    = Math.Abs(dkp_8x8[u1, v1]);
                    Abs2    = Math.Abs(dkp_8x8[u2, v2]);
                    if (Abs1 > Abs2)
                    {
                        bits += "0";
                    }
                    if (Abs1 < Abs2)
                    {
                        bits += "1";
                    }
                }
                else
                {
                    continue;
                }
            }
            steganoMessage.DataBinaryString = bits;
        }