Menu

[r103]: / phprpc_2.1 / keygen / bckeygen_js.php  Maximize  Restore  History

Download this file

32 lines (32 with data), 1.2 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
<?php
require_once('../include/bcmath.php');
$handle = fopen("keypair.js", "w");
fputs($handle, 'var phprpc_keypair = Array(100);' . "\r\n");
for ($i = 0; $i < 100; $i++) {
$f = false;
while (!$f) {
// P1. 利用素性验证算法,生成一个大素数 q;
$q = bcnextprime(bcrand(127, 1));
// P2. 令 p = q * 2 + 1;
$p = bcadd(bcmul($q, '2'), '1');
// P3. 利用素性验证算法,验证 p 是否是素数,如果 p 是合数,则跳转到 P1;
if (bcisprime($p)) $f = true;
}
while ($f) {
// P4. 生成一个随机数 g,1 < g < p - 1;
$g = bcrand(127, 1);
// P5. 验证 g^2 mod p 和 g^q mod p 都不等于 1,否则跳转到 P4;
if ((bcpowmod($g, '2', $p) <> '1') and
(bcpowmod($g, $q, $p) <> '1')) {
$f = false;
}
}
// P6. g 是大素数 p 的本原根。
echo "p = $p\n";
echo "g = $g\n";
fputs($handle, "phprpc_keypair[$i] = [];\r\n");
fputs($handle, "phprpc_keypair[$i]['p'] = '$p';\r\n");
fputs($handle, "phprpc_keypair[$i]['g'] = '$g';\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.