public static void IIA() { Console.WriteLine("I."); Console.WriteLine("Calculating 1233456897 ^ 8001 mod 1783369431"); BigNum num = new BigNum(1233456897); BigNum power = new BigNum(8001); BigNum mod = new BigNum(1783369431); BigNum result = new BigNum(); result = MathOps.Power(num, power, mod); Console.WriteLine(result.DecimalValue); Console.WriteLine(); }
public static void J() { Console.WriteLine("(I) Using DivNum method."); Console.WriteLine("257 / 13 ==> result = 19, reminder 10."); BigNum divided = new BigNum(257L); BigNum divider = new BigNum(13L); BigNum quitient = new BigNum(); BigNum reminder = new BigNum(); MathOps.DivNum(divided, divider, quitient, reminder); Console.WriteLine($"Quitient is: {quitient.WriteNum()}, Reminder is: {reminder.WriteNum()}."); Console.WriteLine(); }
public static void N() { Console.WriteLine("(N) Using IsPrime method."); Console.WriteLine("Checking if 7, 513, 9973, 2147483647. We should get: true, false, true, true."); BigNum n1 = new BigNum(7); BigNum n2 = new BigNum(513); BigNum n3 = new BigNum(9973); BigNum eightMarsenNumber = new BigNum(2147483647); int k = 20; Console.WriteLine(MathOps.IsPrime(n1, k).ToString()); Console.WriteLine(MathOps.IsPrime(n2, k).ToString()); Console.WriteLine(MathOps.IsPrime(n3, k).ToString()); Console.WriteLine(MathOps.IsPrime(eightMarsenNumber, k).ToString()); Console.WriteLine(); }
public static void M() { Console.WriteLine("(M) Using Power method."); Console.WriteLine("Calculating 30^14 mod 7 = 4."); BigNum x = new BigNum(30); BigNum power = new BigNum(14); BigNum mod = new BigNum(7); Console.WriteLine(MathOps.Power(x, power, mod).DecimalValue); Console.WriteLine("Calculating 130^27 mod 41 = 24."); BigNum x2 = new BigNum(130); BigNum power2 = new BigNum(27); BigNum mod2 = new BigNum(41); Console.WriteLine(MathOps.Power(x2, power2, mod2).DecimalValue); Console.WriteLine(); }
public static void L() { Console.WriteLine("(L) Using Inverse method."); BigNum bigNum1 = new BigNum(26); BigNum bigNum2 = new BigNum(21); Console.WriteLine("Calculates the opposite number of 26 mod 21:"); Console.WriteLine(MathOps.Inverse(bigNum1, bigNum2).DecimalValue); Console.WriteLine("Calculates the opposite number of 21 mod 26:"); Console.WriteLine(MathOps.Inverse(bigNum2, bigNum1).DecimalValue); BigNum bigNum3 = new BigNum(15); BigNum bigNum4 = new BigNum(10); Console.WriteLine("Calculates the opposite number of 15 mod 10:"); if (MathOps.Inverse(bigNum3, bigNum4) == null) { Console.WriteLine("There is no opposite for 15"); } Console.WriteLine(); }
public static void K() { Console.WriteLine("(K) Using ExtendedGCD method."); Console.WriteLine("Calculates GCD(26, 21). Should be = 1"); BigNum bigNum3 = new BigNum(26); BigNum bigNum4 = new BigNum(21); BigNum x = new BigNum(); BigNum y = new BigNum(); BigNum gcd = new BigNum(); MathOps.ExtendedGCD(bigNum4, bigNum3, x, y, gcd); Console.WriteLine($"GCD = {gcd.WriteNum()} = {bigNum3.DecimalValue}*{x.DecimalValue}" + $" + {bigNum4.DecimalValue}*{y.DecimalValue}"); Console.WriteLine("Calculates GCD(15, 10). Should be = 5"); BigNum bigNum1 = new BigNum(15); BigNum bigNum2 = new BigNum(10); MathOps.ExtendedGCD(bigNum2, bigNum1, x, y, gcd); Console.WriteLine($"GCD = {gcd.DecimalValue} = {bigNum1.DecimalValue}*{x.DecimalValue}" + $" + {bigNum2.DecimalValue}*{y.DecimalValue}"); Console.WriteLine(); }