public void SignInitialize(int max, int powMin, int powMax) { Console.WriteLine("------------------------------------------------"); max = (int)Math.Pow(2, max); powMin = (int)Math.Pow(2, powMin); powMax = (int)Math.Pow(2, powMax); do { pSign = BigInt.PrimeGenerate(powMin, powMax); Console.WriteLine("P Sign: " + pSign.toString()); qSign = BigInt.PrimeGenerate(powMin, powMax); modSign = BigInt.multiply(pSign, qSign); }while ((BigInt.less(modSign, new BigInt(max.ToString()))) || (BigInt.equal(pSign, qSign))); Console.WriteLine("P Sign: " + pSign.toString()); Console.WriteLine("Q Sign: " + qSign.toString()); Console.WriteLine("mod Sign: " + modSign.toString()); ASign = Karmichael(pSign, qSign); Console.WriteLine("A Sign: " + ASign.toString()); do { do { eSign = BigInt.PrimeGenerate(0, Int32.Parse(ASign.toString())); }while ((BigInt.mod(ASign, eSign)).isZero()); BigInt temp; BigInt.ExtendedGCD(ASign, eSign, out temp, out dSign); }while (BigInt.less(dSign, new BigInt("0"))); Console.WriteLine("E Sign: " + eSign.toString()); Console.WriteLine("D Sign: " + dSign.toString()); Console.WriteLine("------------------------------------------------"); }
public RSA(int max, int powMin, int powMax) { SignInitialize(max, powMin, powMax); max = (int)Math.Pow(2, max); powMin = (int)Math.Pow(2, powMin); powMax = (int)Math.Pow(2, powMax); do { p = BigInt.PrimeGenerate(powMin, powMax); q = BigInt.PrimeGenerate(powMin, powMax); mod = BigInt.multiply(p, q); }while ((BigInt.less(mod, new BigInt(max.ToString()))) || (BigInt.equal(p, q))); Console.WriteLine("P: " + p.toString()); Console.WriteLine("Q: " + q.toString()); Console.WriteLine("mod: " + mod.toString()); A = Karmichael(p, q); Console.WriteLine("A: " + A.toString()); do { do { e = BigInt.PrimeGenerate(0, Int32.Parse(A.toString())); }while ((BigInt.mod(A, e)).isZero()); BigInt temp; BigInt.ExtendedGCD(A, e, out temp, out d); }while (BigInt.less(d, new BigInt("0"))); Console.WriteLine("E: " + e.toString()); Console.WriteLine("D: " + d.toString()); }