Menu

[r202]: / phprpc_2.1 / keygen / keygen_cs.cs  Maximize  Restore  History

Download this file

61 lines (60 with data), 2.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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();
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.