예제 #1
0
        private void ЗвантажитиЗображення_Click(object sender, EventArgs e)
        {
            OpenFileDialog open_dialog = new OpenFileDialog();

            open_dialog.Filter = "Image Files(*.BMP;*.JPG;*.PNG;)|*.BMP;*.JPG;*.PNG|All files (*.*)|*.*";
            if (open_dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    image = new Bitmap(open_dialog.FileName);
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox1.Image    = image;
                    pictureBox1.Invalidate();
                }
                catch
                {
                    DialogResult rezult = MessageBox.Show("Неможливо відкрити зображення",
                                                          "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            ImageDate id = new ImageDate();

            bytes = id.MasByte(image);
            mas   = bytes.Select(i => (int)i).ToArray();

            textBox11.Enabled            = true;
            textBox12.Enabled            = true;
            ШифруватиІнф.Enabled         = true;
            ЗавантажитиФайл.Enabled      = false;
            ЗвантажитиЗображення.Enabled = false;
        }
예제 #2
0
        private void ШифрЗоб_Click(object sender, EventArgs e)
        {
            OpenFileDialog open_dialog = new OpenFileDialog();

            open_dialog.Filter = "Image Files(*.BMP;*.JPG;*.PNG;)|*.BMP;*.JPG;*.PNG|All files (*.*)|*.*";
            if (open_dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    image = new Bitmap(open_dialog.FileName);
                    pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox2.Image    = image;
                    pictureBox2.Invalidate();
                }
                catch
                {
                    DialogResult rezult = MessageBox.Show("Неможливо відкрити зображення",
                                                          "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            ImageDate id = new ImageDate();

            bytes = id.MasByte(image);
            mas   = bytes.Select(i => (int)i).ToArray();

            OpenFileDialog open_dialog1 = new OpenFileDialog();

            open_dialog1.Filter = "Image Files(*.txt)|*.txt|All files (*.*)|*.*";
            if (open_dialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    StreamReader sr = new StreamReader(open_dialog1.FileName);
                    while (!sr.EndOfStream)
                    {
                        sI.Add(sr.ReadLine());
                    }

                    sr.Close();
                }
                catch
                {
                    DialogResult rezult = MessageBox.Show("Неможливо відкрити документ",
                                                          "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            textBox13.Enabled = true;
            textBox14.Enabled = true;
            button5.Enabled   = true;
            button6.Enabled   = false;
        }
예제 #3
0
        private void Дешифрування_Click(object sender, EventArgs e)
        {
            if (textBox4.Text.Length < 0 && pictureBox2.Image == null)
            {
                MessageBox.Show("Заповніть текстове поле, чи завантажте зображення!");
            }
            else
            {
                if (textBox4.Text.Length > 0)
                {
                    if ((textBox13.Text.Length > 0) && (textBox14.Text.Length > 0))
                    {
                        textBox13.Enabled = false;
                        textBox14.Enabled = false;
                        textBox1.Enabled  = false;
                        textBox2.Enabled  = false;
                        button10.Enabled  = false;
                        button6.Enabled   = false;
                        button5.Enabled   = false;
                        button11.Enabled  = false;

                        long d = Convert.ToInt64(textBox13.Text);
                        long n = Convert.ToInt64(textBox14.Text);

                        EncodeDecode ed = new EncodeDecode();
                        resalt = ed.RSA_Dedoce(input, d, n);

                        textBox2.Text = resalt;

                        textBox13.Enabled = true;
                        textBox14.Enabled = true;
                        textBox1.Enabled  = true;
                        textBox2.Enabled  = true;
                        button10.Enabled  = true;
                        button6.Enabled   = true;
                        button5.Enabled   = true;
                        button11.Enabled  = true;
                    }
                    else
                    {
                        MessageBox.Show("Заповніть поля ключів!");
                    }
                }
                if (pictureBox2.Image != null)
                {
                    if ((textBox13.Text.Length > 0) && (textBox14.Text.Length > 0))
                    {
                        textBox13.Enabled = false;
                        textBox14.Enabled = false;
                        textBox1.Enabled  = false;
                        textBox2.Enabled  = false;
                        button10.Enabled  = false;
                        button6.Enabled   = false;
                        button5.Enabled   = false;
                        button11.Enabled  = false;

                        long d = Convert.ToInt64(textBox13.Text);
                        long n = Convert.ToInt64(textBox14.Text);

                        long[] ia = new long[20];
                        int[]  ar = new int[20];

                        ia = sI[0].Split(' ').Select(v => Convert.ToInt64(v)).ToArray();
                        int[] kj = sI[1].Split(' ').Select(v => Convert.ToInt32(v)).ToArray();
                        ar = ia.Select(i => (int)i).ToArray();
                        int[] ms = new int[20];

                        for (int i = 0; i < 20; i++)
                        {
                            ms[i] = mas[ar[i]];
                        }

                        string        rlt = string.Join(" ", kj);
                        List <string> res = rlt.Split(' ').ToList();

                        EncodeDecode ed = new EncodeDecode();
                        resalt = ed.RSA_Dedoce(res, d, n);

                        int[] ai = resalt.Split(' ').Select(k => Convert.ToInt32(k)).ToArray();

                        for (int i = 0; i < 20; i++)
                        {
                            mas[ar[i]] = ai[i];
                        }

                        ImageDate id = new ImageDate();
                        imgFromStream        = id.RetIm(mas);
                        pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
                        pictureBox2.Image    = imgFromStream;

                        textBox13.Enabled = true;
                        textBox14.Enabled = true;
                        textBox1.Enabled  = true;
                        textBox2.Enabled  = true;
                        button10.Enabled  = true;
                        button6.Enabled   = true;
                        button5.Enabled   = true;
                        button11.Enabled  = true;
                    }
                    else
                    {
                        MessageBox.Show("Заповніть поля ключів!");
                    }
                }
            }
        }
예제 #4
0
        private void ШифруватиІнф_Click(object sender, EventArgs e)
        {
            if (textBox4.Text.Length < 0 && pictureBox1.Image == null)
            {
                MessageBox.Show("Заповніть текстове поле, чи завантажте зображення!");
            }
            else
            {
                if (textBox4.Text.Length > 0)
                {
                    if ((textBox11.Text.Length > 0) && (textBox12.Text.Length > 0))
                    {
                        textBox11.Enabled            = false;
                        textBox12.Enabled            = false;
                        textBox4.Enabled             = false;
                        textBox3.Enabled             = false;
                        ШифруватиІнф.Enabled         = false;
                        ЗвантажитиЗображення.Enabled = false;
                        ЗавантажитиФайл.Enabled      = false;
                        Зберигти.Enabled             = false;

                        long e_ = Convert.ToInt64(textBox11.Text);
                        long n  = Convert.ToInt64(textBox12.Text);

                        EncodeDecode ed = new EncodeDecode();
                        result = ed.RSA_Endoce(s, e_, n);


                        for (int i = 0; i < result.Count; i++)
                        {
                            textBox3.Text += result[i] + " ";
                        }

                        textBox11.Enabled            = true;
                        textBox12.Enabled            = true;
                        textBox4.Enabled             = true;
                        textBox3.Enabled             = true;
                        ШифруватиІнф.Enabled         = true;
                        ЗвантажитиЗображення.Enabled = true;
                        ЗавантажитиФайл.Enabled      = true;
                        Зберигти.Enabled             = true;
                    }
                    else
                    {
                        MessageBox.Show("Заповніть поля ключів!");
                    }
                }
                if (pictureBox1.Image != null)
                {
                    if ((textBox11.Text.Length > 0) && (textBox12.Text.Length > 0))
                    {
                        textBox11.Enabled            = false;
                        textBox12.Enabled            = false;
                        textBox4.Enabled             = false;
                        textBox3.Enabled             = false;
                        ШифруватиІнф.Enabled         = false;
                        ЗвантажитиЗображення.Enabled = false;
                        ЗавантажитиФайл.Enabled      = false;
                        Зберигти.Enabled             = false;

                        long e_ = Convert.ToInt64(textBox11.Text);
                        long n  = Convert.ToInt64(textBox12.Text);

                        var   ran = new Random();
                        int[] mos = new int[20];
                        int[] g   = new int[20];

                        for (int i = 0; i < 20; i++)
                        {
                            g[i]   = ran.Next(100, mas.Length);
                            mos[i] = mas[g[i]];
                        }

                        strImg = string.Join(" ", mos);

                        EncodeDecode ed = new EncodeDecode();
                        result = ed.RSA_Endoce(strImg, e_, n);

                        string som = string.Join(" ", result);
                        int[]  ia  = som.Split(' ').Select(w => Convert.ToInt32(w)).ToArray();

                        for (int i = 0; i < 20; i++)
                        {
                            mas[g[i]] = ia[i];
                        }

                        strImg = string.Join(" ", g);
                        stIm   = string.Join(" ", ia);

                        ImageDate id = new ImageDate();
                        imgFromStream        = id.RetIm(mas);
                        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                        pictureBox1.Image    = imgFromStream;

                        textBox11.Enabled            = true;
                        textBox12.Enabled            = true;
                        textBox4.Enabled             = true;
                        textBox3.Enabled             = true;
                        ШифруватиІнф.Enabled         = true;
                        ЗвантажитиЗображення.Enabled = true;
                        ЗавантажитиФайл.Enabled      = true;
                        Зберигти.Enabled             = true;
                    }
                    else
                    {
                        MessageBox.Show("Заповніть поля ключів!");
                    }
                }
            }
        }