Menu

[r202]: / phprpc_2.1 / keygen / bikeygen.php  Maximize  Restore  History

Download this file

36 lines (36 with data), 1.3 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
<?php
$handle = fopen("keypair.php", "w");
fputs($handle, "<"."?php\r\n");
fputs($handle, '$phprpc_keypair = array(' . "\r\n");
$n1 = bi_from_str("1");
$n2 = bi_from_str("2");
for ($i = 0; $i < 100; $i++) {
$f = false;
while (!$f) {
// P1. 利用素性验证算法,生成一个大素数 q;
$q = bi_next_prime(bi_set_bit(bi_rand(127), 126));
// P2. 令 p = q * 2 + 1;
$p = bi_set_bit(bi_lshift($q, 1), 0);
// P3. 利用素性验证算法,验证 p 是否是素数,如果 p 是合数,则跳转到 P1;
if (bi_is_prime($p)) $f = true;
}
while ($f) {
// P4. 生成一个随机数 g,1 < g < p - 1;
$g = bi_set_bit(bi_rand(127), 126);
// P5. 验证 g^2 mod p 和 g^q mod p 都不等于 1,否则跳转到 P4;
if ((bi_powmod($g, $n2, $p) <> $n1) and
(bi_powmod($g, $q, $p) <> $n1)) {
$f = false;
}
}
// P6. g 是大素数 p 的本原根。
$p = bi_to_str($p);
$g = bi_to_str($g);
echo "p = $p\n";
echo "g = $g\n";
fputs($handle, " array('p' => '$p',\r\n");
fputs($handle, " 'g' => '$g'),\r\n");
}
fputs($handle, ");\r\n?".">");
fclose($handle);
?>
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.