using System;
using System.IO;
using Mono.Math;
class KeyGen
{
static void Main(string[] args)
{
StreamWriter sw = new StreamWriter("KeyPairGen.java");
sw.WriteLine("package coolcode.phprpc;");
sw.WriteLine();
sw.WriteLine("import java.lang.*;");
sw.WriteLine("import java.util.*;");
sw.WriteLine();
sw.WriteLine("public class KeyPairGen {");
sw.WriteLine(" private static HashMap[] __keypair = new HashMap[100];");
sw.WriteLine(" private static Random __rand = new Random();");
sw.WriteLine(" private KeyPairGen() {}");
sw.WriteLine(" static {");
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 HashMap();");
sw.WriteLine(" __keypair[" + i.ToString() + "].put(\"p\", \"" + p.ToString() + "\");");
sw.WriteLine(" __keypair[" + i.ToString() + "].put(\"g\", \"" + g.ToString() + "\");");
}
sw.WriteLine(" }");
sw.WriteLine(" public static HashMap genRandomKeyPair() {");
sw.WriteLine(" return __keypair[__rand.nextInt(100)];");
sw.WriteLine(" }");
sw.WriteLine("}");
sw.Close();
}
}