Beispiel #1
0
        public int DecryptC1C2()
        {
            int key = ModuloBase.Power(C1, C2, q);

            Console.WriteLine("Key : " + key);
            int Mdecrypt = (C2 * EulerMethod.ModuloInverse(key, q)) % q;

            return(Mdecrypt);
        }
Beispiel #2
0
 // k=log,a,(b) mod n
 public static int LogarithmRoiRac(int a, int b, int n)
 {
     for (int i = 1; i < n; i++)
     {
         if (b == ModuloBase.Power(a, i, n))
         {
             return(i);
         }
     }
     return(-1);
 }
Beispiel #3
0
        public static int Power(int a, int b, int n)
        {
            int b1;

            if (PrimitiveRoot.IsPrime(n) && a > 0)
            {
                b1 = b % (n - 1);
                return(ModuloBase.Power(a, b1, n));
            }
            return(-1);
        }
Beispiel #4
0
        public static bool isCanNguyenThuy(int a, int n)
        {
            int phiN = EulerMethod.phi(n);

            if (1 == ModuloBase.Power(a, phiN, n))
            {
                for (int i = 1; i < phiN; i++)
                {
                    if (phiN % i == 0)
                    {
                        if (1 == ModuloBase.Power(a, i, n))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
Beispiel #5
0
 public int ADecryptC(int C)
 {
     return(ModuloBase.Power(C, d, n));
 }
Beispiel #6
0
 public int BEncryptM(int M)
 {
     return(ModuloBase.Power(M, e, n));
 }