Ejemplo n.º 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);
        }
Ejemplo n.º 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");
     }
 }