Exemplo n.º 1
0
 protected static function _powmod($x, $y, $m)
 {
     $n = count($y);
     $p = array(1);
     for ($i = 0; $i < $n - 1; $i++) {
         $tmp = $y[$i];
         for ($j = 0; $j < 0xf; $j++) {
             if ($tmp & 1) {
                 $p = BigInt::div(BigInt::mul($p, $x), $m, 1);
             }
             $tmp >>= 1;
             $x = BigInt::div(BigInt::mul($x, $x), $m, 1);
         }
     }
     $tmp = $y[$i];
     while ($tmp) {
         if ($tmp & 1) {
             $p = BigInt::div(BigInt::mul($p, $x), $m, 1);
         }
         $tmp >>= 1;
         $x = BigInt::div(BigInt::mul($x, $x), $m, 1);
     }
     return $p;
 }