Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "")
            {
                MessageBox.Show("Введите n");
                return;
            }

            if (textBox6.Text == "")
            {
                MessageBox.Show("Введите d");
                return;
            }

            LongArithmetic _n = new LongArithmetic();
            LongArithmetic _d = new LongArithmetic();

            try
            {
                _n = LongArithmetic.Parse(textBox3.Text);
                _d = LongArithmetic.Parse(textBox6.Text);
            }
            catch
            {
                MessageBox.Show("Числа невозможно считать!");
                return;
            }

            Console.WriteLine("Начало дешифровки!");

            StringBuilder sbtext = new StringBuilder();

            foreach (string stext in richTextBox2.Lines)
            {
                if (stext == null || stext == "")
                {
                    continue;
                }

                LongArithmetic criptedtext = LongArithmetic.Parse(stext);
                LongArithmetic text        = global::RSA.mypows(criptedtext, _d, _n);

                StringBuilder sb = new StringBuilder();

                foreach (ushort x in text)
                {
                    sb.Append(((char)x).ToString());
                }

                sbtext.Append(sb.ToString());
            }

            richTextBox1.Text = sbtext.ToString();

            Console.WriteLine("Дешифровка закончена!");
        }
Пример #2
0
Файл: RSA.cs Проект: why1799/RSA
    public static LongArithmetic Random()
    {
        //Random rnd = new Random();
        LaggedFibRandom rnd = new LaggedFibRandom((int)(DateTime.UtcNow.ToBinary() % 1000000000));

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < Times; i++)
        {
            sb.Append(rnd.Next() % 10000);
        }

        LongArithmetic res = LongArithmetic.Parse(sb.ToString());

        return(res);
    }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "")
            {
                MessageBox.Show("Введите n");
                return;
            }

            if (textBox5.Text == "")
            {
                MessageBox.Show("Введите e");
                return;
            }

            LongArithmetic _n = new LongArithmetic();
            LongArithmetic _e = new LongArithmetic();

            try
            {
                _n = LongArithmetic.Parse(textBox3.Text);
                _e = LongArithmetic.Parse(textBox5.Text);
            }
            catch
            {
                MessageBox.Show("Числа невозможно считать!");
                return;
            }

            Console.WriteLine("Начало шифрования!");

            StringBuilder sb = new StringBuilder();

            List <ushort>  list        = new List <ushort>();
            LongArithmetic text        = new LongArithmetic();
            LongArithmetic criptedtext = new LongArithmetic();

            richTextBox2.Clear();
            foreach (var c in richTextBox1.Text)
            {
                if ((int)c > 9999 || (int)c < 0)
                {
                    MessageBox.Show("Этот текст содержить невозможные для чтения символы!");
                    return;
                }
                list.Add((ushort)c);
                if (list.Count == 6)
                {
                    text        = new LongArithmetic(list);
                    criptedtext = global::RSA.mypows(text, _e, _n);
                    richTextBox2.AppendText(criptedtext.ToString() + "\n");
                    list.Clear();
                }
            }

            if (list.Count > 0)
            {
                text        = new LongArithmetic(list);
                criptedtext = global::RSA.mypows(text, _e, _n);
                richTextBox2.AppendText(criptedtext.ToString() + "\n");
            }
            Console.WriteLine("Шифровка закончена!");
        }