Example #1
0
        private void BigintGenerate(String input)
        {
            int    size    = input.Length;
            Random r       = new Random();
            int    psize   = size / 2 + 3;
            int    qsize   = size / 2 + 3;
            int    fp      = r.Next();
            int    fq      = r.Next();
            BigInt p       = new BigInt(fp);
            BigInt q       = new BigInt(fq);
            int    counter = 0;

            do
            {
                if (counter > 0)
                {
                    p = new BigInt(psize);
                }
                while (p.size < psize)
                {
                    int tmp = r.Next();
                    p.append(new BigInt(tmp));
                }
                counter = 1;
            } while (BigInt.Prime(p) == false);
            MessageBox.Show(BigInt.UIRes(p));
        }
Example #2
0
        private void mul_button_Click(object sender, EventArgs e)
        {
            String tmp = input.Text;

            A              = new BigInt(tmp);
            input.Text     = "";
            full_text.Text = BigInt.UIRes(A) + " * ";
            power          = false;
            mod            = false;
            div            = false;
            plus           = false;
            minus          = false;
            mul            = true;
        }
Example #3
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                start_button.Text = "Working ...";
                textBox1.Text     = "";
                Time.Text         = "";
                String       s = "";
                String       tmpED;
                String       tmpM;
                String       tmp_N;
                String       check;
                int          start = System.Environment.TickCount;
                FileStream   file  = new FileStream(file_dir_text.Text, FileMode.Open);
                StreamReader SR    = new StreamReader(file);

                int test = int.Parse(SR.ReadLine());
                while (SR.Peek() != -1)
                {
                    tmp_N = SR.ReadLine();
                    BigInt N = new BigInt(tmp_N);
                    tmpED = SR.ReadLine();
                    BigInt ED = new BigInt(tmpED);
                    tmpM = SR.ReadLine();
                    BigInt M   = new BigInt(tmpM);
                    BigInt res = BigInt.En_Decrytion(ED, N, M);
                    check = SR.ReadLine();
                    String fres = BigInt.UIRes(res);
                    s             += fres + Environment.NewLine;
                    textBox1.Text += fres + Environment.NewLine + Environment.NewLine;
                    progressBar.Increment(100 / test);
                }
                int    end = System.Environment.TickCount;
                double dif = TimeSpan.FromMilliseconds(end - start).TotalSeconds;
                Time.Text = dif.ToString();
                SR.Close();
                file.Close();
                progressBar.Value = 100;
                start_button.Text = "Start";
                MessageBox.Show("File has Been Encrypted", "Done");
            }
            catch
            {
                MessageBox.Show("File doesn't Exist", "Error");
            }
        }
Example #4
0
        private void equal_button_Click(object sender, EventArgs e)
        {
            try
            {
                int    start, end;
                double dif;
                String tmp = input.Text;
                B = new BigInt(tmp);
                full_text.Text += BigInt.UIRes(B);
                if (plus == true)
                {
                    start = System.Environment.TickCount;
                    Res   = A + B;
                    end   = System.Environment.TickCount;
                    dif   = TimeSpan.FromMilliseconds(end - start).TotalSeconds;
                    operation_time.Text = dif.ToString();
                    input.Text          = BigInt.UIRes(Res);
                }
                else if (minus == true)
                {
                    start = System.Environment.TickCount;
                    Res   = A - B;
                    end   = System.Environment.TickCount;
                    dif   = TimeSpan.FromMilliseconds(end - start).TotalSeconds;
                    operation_time.Text = dif.ToString();
                    input.Text          = BigInt.UIRes(Res);
                }

                else if (div == true)
                {
                    BigInt[] res2 = new BigInt[2];
                    start = System.Environment.TickCount;
                    res2  = A / B;
                    end   = System.Environment.TickCount;
                    dif   = TimeSpan.FromMilliseconds(end - start).TotalSeconds;
                    operation_time.Text = dif.ToString();
                    input.Text          = BigInt.UIRes(res2[0]);
                }
                else if (mul == true)
                {
                    start = System.Environment.TickCount;
                    Res   = A * B;
                    end   = System.Environment.TickCount;
                    dif   = TimeSpan.FromMilliseconds(end - start).TotalSeconds;
                    operation_time.Text = dif.ToString();
                    input.Text          = BigInt.UIRes(Res);
                }
                else if (power == true)
                {
                    start = System.Environment.TickCount;
                    Res   = A ^ B;
                    end   = System.Environment.TickCount;
                    dif   = TimeSpan.FromMilliseconds(end - start).TotalSeconds;
                    operation_time.Text = dif.ToString();
                    input.Text          = BigInt.UIRes(Res);
                }
                else if (mod == true)
                {
                    start = System.Environment.TickCount;
                    Res   = A % B;
                    end   = System.Environment.TickCount;
                    dif   = TimeSpan.FromMilliseconds(end - start).TotalSeconds;
                    operation_time.Text = dif.ToString();
                    input.Text          = BigInt.UIRes(Res);
                }
                else
                {
                    operation_time.Text = "";
                    full_text.Text      = "";
                    MessageBox.Show("You haven't chosen any Function", "Error");
                }
                plus  = false;
                minus = false;
                div   = false;
                mul   = false;
            }
            catch {
                MessageBox.Show("Something Went Wrong ", "Error");
            }
        }