Ejemplo n.º 1
0
        private void RunAlgorithm()
        {
            switch (algorithm)
            {
                case "LSB Hiding":
                    try
                    {
                        LSBHiding lsb = new LSBHiding(hostImage, secretImage);
                        lsb.NumberOfBits = numberOfBits;

                        DataTable dt = new DataTable();
                        dt.Columns.Add("Bit");
                        dt.Columns.Add("PSNR R");
                        dt.Columns.Add("PSNR G");
                        dt.Columns.Add("PSNR B");
                        dt.Columns.Add("PSNR GY");

                        switch (type)
                        {
                            case "LSB-LSB":
                                lsb.LSB_LSB();
                                outputImage = (Bitmap)lsb.OutputImage.Clone();
                                lsb.saveOutputImage(path, "OutputImage_" + type + "_" + numberOfBits.ToString() + ".bmp");
                                for (int i = 1; i <= 7; i++)
                                {
                                    lsb.NumberOfBits = i;
                                    lsb.LSB_LSB();
                                    PSNR psnr = new PSNR(hostImage, lsb.OutputImage);
                                    dt.Rows.Add(i.ToString(), psnr.R.ToString(), psnr.G.ToString(), psnr.B.ToString(), psnr.Gray.ToString());

                                    lsb.saveOutputImage(path, "OutputImage_" + type + "_" + i.ToString() + ".bmp");
                                }
                                analysisForm.SetPSNRForDataGrid(dt);
                                break;

                            case "LSB-MSB":
                                lsb.LSB_MSB();
                                outputImage = (Bitmap)lsb.OutputImage.Clone();
                                lsb.saveOutputImage(path, "OutputImage_" + type + "_" + numberOfBits.ToString() + ".bmp");
                                for (int i = 1; i <= 7; i++)
                                {
                                    lsb.NumberOfBits = i;
                                    lsb.LSB_MSB();
                                    PSNR psnr = new PSNR(hostImage, lsb.OutputImage);
                                    dt.Rows.Add(i.ToString(), psnr.R.ToString(), psnr.G.ToString(), psnr.B.ToString(), psnr.Gray.ToString());

                                    lsb.saveOutputImage(path, "OutputImage_" + type + "_" + i.ToString() + ".bmp");
                                }
                                analysisForm.SetPSNRForDataGrid(dt);
                                break;
                        }

                        outputImageBox.Image = (Image)outputImage;

                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(
                            E.ToString(),
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    break;

                case "Visual Cryptography":
                    try
                    {
                        VisualCryptography vc = new VisualCryptography(hostImage, secretImage);
                        vc.NumberOfBits = numberOfBits;
                        vc.CreateShareImages();
                        vc.saveShareImage1(path, "ShareImage1.bmp");
                        vc.saveShareImage2(path, "ShareImage2.bmp");

                        DataTable dt = new DataTable();
                        dt.Columns.Add("Bit");
                        dt.Columns.Add("PSNR R");
                        dt.Columns.Add("PSNR G");
                        dt.Columns.Add("PSNR B");
                        dt.Columns.Add("PSNR GY");

                        switch (type)
                        {
                            case "LSB-LSB":
                                vc.LSB_LSB();
                                outputImage = (Bitmap)vc.OutputImage.Clone();
                                vc.saveOutputImage(path, "OutputImage_" + type + "_" + numberOfBits.ToString() + ".bmp");
                                for (int i = 1; i <= 7; i++)
                                {
                                    vc.NumberOfBits = i;
                                    vc.LSB_LSB();
                                    PSNR psnr = new PSNR(hostImage, vc.OutputImage);
                                    dt.Rows.Add(i.ToString(), psnr.R.ToString(), psnr.G.ToString(), psnr.B.ToString(), psnr.Gray.ToString());

                                    vc.saveOutputImage(path, "OutputImage_" + type + "_" + i.ToString() + ".bmp");
                                }
                                analysisForm.SetPSNRForDataGrid(dt);
                                break;

                            case "LSB-MSB":
                                vc.LSB_MSB();
                                outputImage = (Bitmap)vc.OutputImage.Clone();
                                vc.saveOutputImage(path, "OutputImage_" + type + "_" + numberOfBits.ToString() + ".bmp");
                                for (int i = 1; i <= 7; i++)
                                {
                                    vc.NumberOfBits = i;
                                    vc.LSB_MSB();
                                    PSNR psnr = new PSNR(hostImage, vc.OutputImage);
                                    dt.Rows.Add(i.ToString(), psnr.R.ToString(), psnr.G.ToString(), psnr.B.ToString(), psnr.Gray.ToString());

                                    vc.saveOutputImage(path, "OutputImage_" + type + "_" + i.ToString() + ".bmp");
                                }
                                analysisForm.SetPSNRForDataGrid(dt);
                                break;
                        }

                        outputImageBox.Image = (Image)outputImage;
                        secretImage = vc.SecretImage;

                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(
                            E.ToString(),
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    break;

                case "Randomized LSB Hiding":
                    try
                    {
                        RandomizedLSBHiding rlsb = new RandomizedLSBHiding(hostImage, secretImage, numberOfRndNumbers, direction);
                        rlsb.NumberOfBits = numberOfBits;
                        rlsb.GenerateRandomNumbers();

                        DataTable dt = new DataTable();
                        dt.Columns.Add("Bit");
                        dt.Columns.Add("PSNR R");
                        dt.Columns.Add("PSNR G");
                        dt.Columns.Add("PSNR B");
                        dt.Columns.Add("PSNR GY");

                        switch (type)
                        {
                            case "LSB-LSB":
                                rlsb.LSB_LSB();
                                outputImage = (Bitmap)rlsb.OutputImage.Clone();
                                rlsb.saveOutputImage(path, "OutputImage_" + type + "_" + numberOfBits.ToString() + "_" + numberOfRndNumbers.ToString() + ".bmp");
                                for (int i = 1; i <= 7; i++)
                                {
                                    rlsb.NumberOfBits = i;
                                    rlsb.LSB_LSB();
                                    PSNR psnr = new PSNR(hostImage, rlsb.OutputImage);
                                    dt.Rows.Add(i.ToString(), psnr.R.ToString(), psnr.G.ToString(), psnr.B.ToString(), psnr.Gray.ToString());

                                    rlsb.saveOutputImage(path, "OutputImage_" + type + "_" + i.ToString() + "_" + numberOfRndNumbers.ToString() + ".bmp");
                                }
                                analysisForm.SetPSNRForDataGrid(dt);
                                break;

                            case "LSB-MSB":
                                rlsb.LSB_MSB();
                                outputImage = (Bitmap)rlsb.OutputImage.Clone();
                                rlsb.saveOutputImage(path, "OutputImage_" + type + "_" + numberOfBits.ToString() + "_" + numberOfRndNumbers.ToString() + ".bmp");
                                for (int i = 1; i <= 7; i++)
                                {
                                    rlsb.NumberOfBits = i;
                                    rlsb.LSB_MSB();
                                    PSNR psnr = new PSNR(hostImage, rlsb.OutputImage);
                                    dt.Rows.Add(i.ToString(), psnr.R.ToString(), psnr.G.ToString(), psnr.B.ToString(), psnr.Gray.ToString());

                                    rlsb.saveOutputImage(path, "OutputImage_" + type + "_" + i.ToString() + "_" + numberOfRndNumbers.ToString() + ".bmp");
                                }
                                analysisForm.SetPSNRForDataGrid(dt);
                                break;
                        }

                        outputImageBox.Image = (Image)outputImage;
                        secretImage = rlsb.SecretImage;

                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(
                            E.ToString(),
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    break;

                case "Interlaced Bit Hiding":
                    try
                    {
                        analysisForm.HidePSNRDataGridView();
                        InterlacedBitHiding ibh = new InterlacedBitHiding(hostImage, secretImage);
                        switch (type)
                        {
                            case "Odd-Even":
                                ibh.Odd_Even();
                                outputImage = (Bitmap)ibh.OutputImage.Clone();
                                ibh.saveOutputImage(path, "OutputImage_" + type + ".bmp");
                                break;

                            case "Pair-Wise":
                                ibh.Pair_Wise();
                                outputImage = (Bitmap)ibh.OutputImage.Clone();
                                ibh.saveOutputImage(path, "OutputImage_" + type + ".bmp");
                                break;
                        }

                        outputImageBox.Image = (Image)outputImage;
                        secretImage = ibh.SecretImage;

                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(
                            E.ToString(),
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    break;
                default:
                    MessageBox.Show(
                        "Please select algorithm!",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    break;
            }
        }
Ejemplo n.º 2
0
        private void DeRunAlgorithm()
        {
            switch (algorithm)
            {
                case "LSB Hiding":
                    try
                    {
                        LSBHiding lsb = new LSBHiding(outputImage);
                        lsb.NumberOfBits = numberOfBits;

                        switch (type)
                        {
                            case "LSB-LSB":
                                lsb.Reverse_LSB_LSB();
                                break;

                            case "LSB-MSB":
                                lsb.Reverse_LSB_MSB();
                                break;
                        }

                        secretImage = (Bitmap)lsb.SecretImage.Clone();
                        secretImageBox.Image = (Image)secretImage;

                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(
                            E.ToString(),
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    break;

                case "Visual Cryptography":
                    try
                    {
                        Bitmap shareImage2;
                        OpenFileDialog dlgSelectShareImage2 = new OpenFileDialog();
                        dlgSelectShareImage2.Title = "Select Share Image 2 File";
                        dlgSelectShareImage2.Filter = "Image Files|*.bmp";
                        dlgSelectShareImage2.FilterIndex = 1;
                        dlgSelectShareImage2.Multiselect = false;

                        if (dlgSelectShareImage2.ShowDialog() == DialogResult.OK)
                        {
                            if (dlgSelectShareImage2.FileName == String.Empty)
                                return;

                            shareImage2 = new Bitmap(dlgSelectShareImage2.FileName);
                        }
                        else
                        {
                            return;
                        }

                        VisualCryptography vc = new VisualCryptography(outputImage);
                        vc.ShareImage2 = shareImage2;
                        vc.NumberOfBits = numberOfBits;

                        switch (type)
                        {
                            case "LSB-LSB":
                                vc.Reverse_LSB_LSB();
                                break;

                            case "LSB-MSB":
                                vc.Reverse_LSB_MSB();
                                break;
                        }

                        vc.CreateSecretImage();
                        secretImage = (Bitmap)vc.SecretImage.Clone();
                        secretImageBox.Image = (Image)secretImage;

                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(
                            E.ToString(),
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    break;

                case "Randomized LSB Hiding":
                    try
                    {
                        RandomizedLSBHiding rlsb = new RandomizedLSBHiding(outputImage, numberOfRndNumbers, direction);
                        rlsb.NumberOfBits = numberOfBits;
                        rlsb.GenerateRandomNumbers();

                        switch (type)
                        {
                            case "LSB-LSB":
                                rlsb.Reverse_LSB_LSB();
                                break;

                            case "LSB-MSB":
                                rlsb.Reverse_LSB_MSB();
                                break;
                        }

                        secretImage = (Bitmap)rlsb.SecretImage.Clone();
                        secretImageBox.Image = (Image)secretImage;

                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(
                            E.ToString(),
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    break;

                case "Interlaced Bit Hiding":
                    try
                    {
                        InterlacedBitHiding ibh = new InterlacedBitHiding(outputImage);

                        switch (type)
                        {
                            case "Odd-Even":
                                ibh.Reverse_Odd_Even();
                                break;

                            case "Pair-Wise":
                                ibh.Reverse_Pair_Wise();
                                break;
                        }

                        secretImage = (Bitmap)ibh.SecretImage.Clone();
                        secretImageBox.Image = (Image)secretImage;

                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(
                            E.ToString(),
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    break;
                default:
                    MessageBox.Show(
                        "Please select algorithm!",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    break;
            }
        }