예제 #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
 function bccomp($a, $b)
 {
     return bi_cmp($a, $b);
 }
예제 #3
0
파일: example.php 프로젝트: garybulin/php7
echo '$a * $b = [', bi_to_str($c), "]<br/>\n";
$c = bi_div($a, $b);
echo '$a / $b = [', bi_to_str($c), "]<br/>\n";
$c = bi_mod($a, $b);
echo '$a % $b = [', bi_to_str($c), "]<br/>\n";
$c = bi_abs($a);
echo 'abs($a) = [', bi_to_str($c), "]<br/>\n";
$c = bi_neg($a);
echo 'neg($a) = [', bi_to_str($c), "]<br/>\n";
$c = bi_inc($a);
echo 'inc($a) = [', bi_to_str($c), "]<br/>\n";
$c = bi_dec($a);
echo 'dec($a) = [', bi_to_str($c), "]<br/>\n";
$c = bi_sqr($a);
echo 'sqr($a) = [', bi_to_str($c), "]<br/>\n";
echo 'cmp($a, $b) = ', bi_cmp($a, $b), "<br/>\n";
echo 'cmp_abs($a, $b) = ', bi_cmp_abs($a, $b), "<br/>\n";
echo 'is_zero($a) = ', bi_is_zero($a) ? 'true' : 'false', "<br/>\n";
echo 'is_one($a) = ', bi_is_one($a) ? 'true' : 'false', "<br/>\n";
echo 'sign($a) = ', bi_sign($a), "<br/>\n";
/*
    bitset functions
*/
echo '<h3>bitset functions</h3>' . "\n";
echo '<div style="text-align:right">';
echo '$a = [', bi_to_str($a, 2), "]<br/>\n";
echo '$b = [', bi_to_str($b, 2), "]<br/>\n";
$c = bi_or($a, $b);
echo '$a or $b = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_xor($a, $b);
echo '$a xor $b = [', bi_to_str($c, 2), "]<br/>\n";
 /**
  * Compare two arbitrary precision numbers
  *
  * @param string $a The left operand, as a string.
  * @param string $b The right operand, as a string.
  * @access public
  * @return int Returns 0 if the two operands are equal, 1 if the left_operand is larger than the right_operand, -1 otherwise.
  */
 public function cmp($a, $b)
 {
     return bi_cmp($a, $b);
 }