Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int        f_time = System.Environment.TickCount;
            BigInteger ob     = new BigInteger();

            if (Integer.Checked)
            {
                if (ob.IsSmaller(mess.Text, n.Text))
                {
                    res.Text = ob.FindMod(mess.Text, pow.Text, n.Text);
                }
                else
                {
                    MessageBox.Show("please make sure the the message you entered is smaller than the N ", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (Text.Checked)
            {
                byte[] r   = Encoding.ASCII.GetBytes(mess.Text);
                String MSG = String.Join("", r);
                if (ob.IsSmaller(MSG, n.Text))
                {
                    res.Text = ob.FindMod(MSG, pow.Text, n.Text);
                }
                else
                {
                    MessageBox.Show("please make sure the the message you entered is smaller than the N ", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            long s_time = System.Environment.TickCount;
            long time   = s_time - f_time;

            MessageBox.Show(FormatTime(time));
        }
Example #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            long          f_time = System.Environment.TickCount;
            BigInteger    ob     = new BigInteger();
            StringBuilder result = new StringBuilder("");
            BigInteger    msg    = new BigInteger(mess.Text);
            BigInteger    power  = new BigInteger(pow.Text);
            BigInteger    N      = new BigInteger(n.Text);
            BigInteger    sol    = new BigInteger("");

            if (Integer.Checked)
            {
                if (ob.IsSmaller(mess.Text, n.Text))
                {
                    //res.Text= ob.FindMod(mess.Text, pow.Text, n.Text);
                    sol      = ob.FindMod(msg, power, N);
                    res.Text = sol.ToString();
                }
                else
                {
                    MessageBox.Show("please make sure that the message you entered is smaller than the N ", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (Text.Checked)
            {
                if (ob.IsSmaller(mess.Text, n.Text))
                {
                    sol = ob.FindMod(msg, power, N);
                    string s = sol.ToString();

                    for (int i = 0; i < s.Length; i++)
                    {
                        string curr    = "";
                        int    current = 0;
                        if (s[i] == '9')
                        {
                            curr = s.Substring(i, 2);
                            i   += 1;
                        }
                        else if (s[i] == '1')
                        {
                            curr = s.Substring(i, 3);
                            i   += 2;
                        }
                        current = Convert.ToInt32(curr);
                        result.Append((Convert.ToChar(current)).ToString());
                    }
                    res.Text = result.ToString();
                }
                else
                {
                    MessageBox.Show("please make sure the the message you entered is smaller than the N ", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            long s_time = System.Environment.TickCount;
            long time   = s_time - f_time;

            MessageBox.Show(FormatTime(time));
        }
Example #3
0
        private void button4_Click(object sender, EventArgs e)
        {
            long         f_time = 0, time = 0, s_time = 0;
            BigInteger   inst       = new BigInteger();
            FileStream   sample_rsa = new FileStream("TestRSA.txt", FileMode.Open, FileAccess.Read);
            StreamReader sr         = new StreamReader(sample_rsa);
            int          count      = int.Parse(sr.ReadLine());
            FileStream   sample_out = new FileStream("TestRSA_Out.txt", FileMode.Append, FileAccess.Write);
            TextWriter   output     = new StreamWriter(sample_out);

            while (count > 0)
            {
                string     N      = sr.ReadLine();
                string     E_orD  = sr.ReadLine();
                string     M_orEM = sr.ReadLine();
                int        option = int.Parse(sr.ReadLine());
                BigInteger msg    = new BigInteger(M_orEM);
                BigInteger power  = new BigInteger(E_orD);
                BigInteger NN     = new BigInteger(N);
                BigInteger sol    = new BigInteger("");
                if (option == 0)
                {
                    f_time = System.Environment.TickCount;  // time before
                    DateTime before = DateTime.Now;
                    sol = inst.FindMod(msg, power, NN);
                    string result = sol.ToString();
                    output.WriteLine(result);
                    //*******************time after***************************
                    s_time = System.Environment.TickCount;
                    time   = s_time - f_time;
                    MessageBox.Show(FormatTime(time));
                    //********************************************************
                    // MessageBox.Show("result=", result);
                }
                else if (option == 1)
                {
                    f_time = System.Environment.TickCount;  // time before
                    sol    = inst.FindMod(msg, power, NN);
                    string result = sol.ToString();
                    output.WriteLine(result);
                    //*******************time after***************************
                    s_time = System.Environment.TickCount;
                    time   = s_time - f_time;
                    MessageBox.Show(FormatTime(time));
                    //********************************************************
                    //MessageBox.Show("result=", result);
                }

                count--;
            }
            sr.Close();
            sample_rsa.Close();
            output.Close();
            sample_out.Close();
            MessageBox.Show("Add output file has been created successfully ^o^");
        }
Example #4
0
        private void button4_Click(object sender, EventArgs e)
        {
            BigInteger   inst       = new BigInteger();
            FileStream   sample_rsa = new FileStream("TestRSA.txt", FileMode.Open, FileAccess.Read);
            StreamReader sr         = new StreamReader(sample_rsa);
            int          count      = int.Parse(sr.ReadLine());
            FileStream   sample_out = new FileStream("TestRSA_Out.txt", FileMode.Append, FileAccess.Write);
            TextWriter   output     = new StreamWriter(sample_out);

            while (count > 0)
            {
                string N      = sr.ReadLine();
                string E_orD  = sr.ReadLine();
                string M_orEM = sr.ReadLine();
                int    option = int.Parse(sr.ReadLine());
                if (option == 0)
                {
                    DateTime before = DateTime.Now;
                    string   result = inst.FindMod(M_orEM, E_orD, N);

                    output.WriteLine(result);
                    MessageBox.Show("result=", result);
                }
                else if (option == 1)
                {
                    string result = inst.FindMod(M_orEM, E_orD, N);
                    output.WriteLine(result);
                    MessageBox.Show("result=", result);
                }

                count--;
            }
            sr.Close();
            sample_rsa.Close();
            output.Close();
            sample_out.Close();
            MessageBox.Show("Add output file has been created successfully ^o^");
        }