using System;
using System.IO;
using Mono.Math;
class KeyGen
{
static void Main(string[] args)
{
StreamWriter sw = new StreamWriter("KeyPair.cs");
sw.WriteLine("using System;");
sw.WriteLine("using System.Collections;");
sw.WriteLine("namespace PHPRPC");
sw.WriteLine("{");
sw.WriteLine(" public class KeyPairGen");
sw.WriteLine(" {");
sw.WriteLine(" private static Hashtable[] __keypair;");
sw.WriteLine(" private static Random __rand;");
sw.WriteLine(" private KeyPairGen()");
sw.WriteLine(" {");
sw.WriteLine(" }");
sw.WriteLine(" static KeyPairGen()");
sw.WriteLine(" {");
sw.WriteLine(" __keypair = new Hashtable[100];");
sw.WriteLine(" __rand = new Random();");
BigInteger n1 = new BigInteger(1);
BigInteger n2 = new BigInteger(2);
for (int i = 0; i < 100; i++)
{
bool f = false;
BigInteger q = null, p = null, g = null;
while (!f)
{
q = BigInteger.GeneratePseudoPrime(127);
p = q << 1;
p.SetBit(0);
if (p.IsProbablePrime()) f = true;
}
while (f)
{
g = BigInteger.GenerateRandom(127);
if (g.ModPow(n2, p) != n1 && g.ModPow(q, p) != n1)
{
f = false;
}
}
Console.WriteLine("p=" + p.ToString());
Console.WriteLine("g=" + g.ToString());
sw.WriteLine(" __keypair[" + i.ToString() + "] = new Hashtable();");
sw.WriteLine(" __keypair[" + i.ToString() + "][\"p\"] = \"" + p.ToString() + "\";");
sw.WriteLine(" __keypair[" + i.ToString() + "][\"g\"] = \"" + g.ToString() + "\";");
}
sw.WriteLine(" }");
sw.WriteLine(" public static Hashtable genRandomKeyPair()");
sw.WriteLine(" {");
sw.WriteLine(" return __keypair[__rand.Next(100)];");
sw.WriteLine(" }");
sw.WriteLine(" }");
sw.WriteLine("}");
sw.Close();
}
}