예제 #1
0
        public static int GiaiMaRSA(int p, int q, int C)
        {
            Khoa khoacongkhai = new Khoa();
            Khoa khoabimat    = new Khoa();
            int  N            = p * q;
            int  n            = (p - 1) * (q - 1);
            int  e            = 0;

            for (int i = 2; i < n; i++)
            {
                SoKetQua kq = GiaiThuat.TinhEuclid(i, n);
                if (kq.Ucln == 1)
                {
                    e = i;
                    break;
                }
            }
            int d = GiaiThuat.TinhEuclid(n, e).Nghichdao;

            khoacongkhai.So1 = e;
            khoacongkhai.So2 = N;
            khoabimat.So1    = d;
            khoabimat.So2    = N;
            int Mngang = binhphuonglientiep(C, d, N);

            return(Mngang);
        }
예제 #2
0
 private void button1_Click(object sender, EventArgs e1)
 {
     try
     {
         int  p            = Convert.ToInt32(txtp.Text);
         int  q            = Convert.ToInt32(txtq.Text);
         Khoa khoacongkhai = new Khoa();
         Khoa khoabimat    = new Khoa();
         int  N            = p * q;
         int  n            = (p - 1) * (q - 1);
         int  e            = 0;
         for (int i = 2; i < n; i++)
         {
             SoKetQua kq = GiaiThuat.TinhEuclid(i, n);
             if (kq.Ucln == 1)
             {
                 e = i;
                 break;
             }
             else
             {
                 continue;
             }
         }
         int d = GiaiThuat.TinhEuclid(n, e).Nghichdao;
         txte.Text  = e.ToString();
         txtN.Text  = N.ToString();
         txtd.Text  = d.ToString();
         txtN2.Text = N.ToString();
     }
     catch
     {
         MessageBox.Show("Có lỗi xảy ra");
     }
 }
예제 #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         SoKetQua a = TinhEuclid(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text));
         textBox3.Text = a.Ucln.ToString();
         textBox4.Text = a.Nghichdao.ToString();
     }
     catch
     {
         MessageBox.Show("Có lỗi ");
     }
 }
예제 #4
0
        public static SoKetQua TinhEuclid(int a, int b)
        {
            SoKetQua kq = new SoKetQua();
            int      A1 = 1;
            int      A2 = 0;
            int      A3 = a;
            int      B1 = 0;
            int      B2 = 1;
            int      B3 = b;
            int      Q  = 0;
            int      R1 = 0;
            int      R2 = 0;
            int      R3 = 0;

            while (B3 != 0 && B3 != 1)
            {
                Q  = A3 / B3;
                R1 = A1 - (Q * B1);
                R2 = A2 - (Q * B2);
                R3 = A3 - (Q * B3);
                A1 = B1;
                A2 = B2;
                A3 = B3;
                B1 = R1;
                B2 = R2;
                B3 = R3;
            }
            if (B3 == 0)
            {
                kq.Ucln      = A3;
                kq.Nghichdao = 0;
                return(kq);
            }
            else
            {
                kq.Ucln = 1;
                if (B2 < 0)
                {
                    kq.Nghichdao = B2 + a;
                }
                else
                {
                    kq.Nghichdao = B2;
                }
                return(kq);
            }
        }