Ejemplo n.º 1
0
function biPowMod($x, $y, $m)
{
    global $biRadixBase, $biRadixBits, $biBitsPerDigit, $biRadix, $biHalfRadix, $biRadixSquared, $biMaxDigitVal, $biMaxInteger, $biMaxDigits, $biZERO_ARRAY, $biBigZero, $biBigOne, $dpl10, $lr10;
    $result = $biBigOne;
    $a = $x;
    $k = $y;
    while (true) {
        if (($k->digits[0] & 1) != 0) {
            $result = biMultiplyMod($result, $a, $m);
        }
        $k = biShiftRight($k, 1);
        if ($k->digits[0] == 0 && biHighIndex($k) == 0) {
            break;
        }
        $a = biMultiplyMod($a, $a, $m);
    }
    return $result;
}
Ejemplo n.º 2
0
 function powMod($x, $y)
 {
     $result = new BigInt();
     $result->digits[0] = 1;
     $a = $x;
     $k = $y;
     while (true) {
         if (($k->digits[0] & 1) != 0) {
             $result = $this->multiplyMod($result, $a);
         }
         $k = biShiftRight($k, 1);
         if ($k->digits[0] == 0 && biHighIndex($k) == 0) {
             break;
         }
         $a = $this->multiplyMod($a, $a);
     }
     return $result;
 }