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        - [EMAIL PROTECTED]
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:   [EMAIL PROTECTED]
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


-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to