コード例 #1
0
ファイル: RSA.php プロジェクト: garybulin/php7
/**
    encrypts / decrypts $text with key ($e, $n)
*/
function encrypt_text($text, $e, $n)
{
    $tmp = bi_unserialize($text);
    $e = bi_unserialize($e);
    $n = bi_unserialize($n);
    if (bi_cmp($tmp, $n) >= 0) {
        die('$text is too long to encrypt by key with length ' . bi_bit_len($n) . ' bits' . "<br/>\n");
    }
    return bi_serialize(bi_powmod($tmp, $e, $n));
}
コード例 #2
0
ファイル: BigInt.php プロジェクト: helenadeus/s3db.map
 /**
  * Returns bit length of number $num
  *
  * @param big_int resource $num
  * @return int
  * @access public
  */
 function bitLen($num)
 {
     return bi_bit_len($num);
 }
コード例 #3
0
ファイル: example.php プロジェクト: garybulin/php7
echo '$a andnot $b = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_set_bit($a, 0);
echo 'set_bit($a, 0) = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_clr_bit($a, 0);
echo 'clr_bit($a, 0) = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_inv_bit($a, 0);
echo 'inv_bit($a, 0) = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_subint($a, 10, 20);
echo 'subint($a, 10, 20) = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_rshift($a, 10);
echo '$a >> 10 = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_lshift($a, 10);
echo '$a << 10 = [', bi_to_str($c, 2), "]<br/>\n";
echo '</div>', "<br/>\n";
echo 'Hamming distance($a, $b) = ', bi_hamming_distance($a, $b), "<br/>\n";
echo 'bit_len($a) = ', bi_bit_len($a), "<br/>\n";
echo 'bit1_cnt($a) = ', bi_bit1_cnt($a), "<br/>\n";
echo 'test_bit($a, 0) = ', bi_test_bit($a, 0), "<br/>\n";
echo 'scan0_bit($a, 0) = ', bi_scan0_bit($a, 0), "<br/>\n";
echo 'scan1_bit($a, 0) = ', bi_scan1_bit($a, 0), "<br/>\n";
echo '<h3>pseudorandom functions</h3>' . "\n";
/* 
    resource bi_rand(int $bit_len[, string $rand_func_name])
    Returns pseudorandom number with $bit_len bit length.
    Attention: do not use this function in cryptographic
    or security applications! The function can be used only
    for educational purposes :)
*/
$c = bi_rand(100);
echo 'rand(100) = ', bi_to_str($c), "<br/>\n";
$c = bi_rand(100, 'mt_rand');