Re: bcpowmod() and bigIntegers

From: Date: Sat, 22 Feb 2003 20:40:50 +0000
Subject: Re: bcpowmod() and bigIntegers
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-94472@lists.php.net to get a copy of this message
Hi, Robert Kofler wrote:
is there a possibility to implement bcpowmod() in a version prior than PHP5? bcpowmod() ist the only way to calculate a blind signature as described by David CHAUM 1982 -> digicash (openssl does not work here). try this:
function bcPowMod($n, $e, $m) { //if ($m == 0 || $e < 0) return 0; if (bccomp($m, 0) == 0 || bccomp($e, 0) == -1) return 0; $res = 1; $pow = $n; $e1 = $e; //while ($e1 != 0) { while (bccomp($e1, 0) != 0) {
      $d = bcmod($e1, 2);
      //$e1  = floor(bcdiv($e1, 2));
      $e1  = bcdiv($e1, 2, 0);
      //if ($d == 1) {
      if (bccomp($d, 1) == 0) {
         $res = bcMod(bcMul($res, $pow), $m);
      }
      $pow = bcMod(bcMul($pow, $pow), $m);
} // if ($res < 0) if (bccomp($res, 0) == -1) $res = bcAdd($res, $m); return $res; } bye, -- ------------------------------- ------------------------------------- Michael Bretterklieber - Michael.Bretterklieber@jawa.at JAWA Management Software GmbH - http://www.jawa.at Liebenauer Hauptstr. 200 -------------- privat --------------- A-8041 GRAZ GSM: ++43-(0)676-93 96 698 Tel: ++43-(0)316-403274-12 E-mail: michael@bretterklieber.com Fax: ++43-(0)316-403274-10 http://www.bretterklieber.com ------------------------------- ------------------------------------- "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972

« previous php.dev (#94472) next »