• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Crypt/Math/BigInteger/Bcmath.php

00001 <?php
00026 require_once 'Zend/Crypt/Math/BigInteger/Interface.php';
00027 
00039 class Zend_Crypt_Math_BigInteger_Bcmath implements Zend_Crypt_Math_BigInteger_Interface
00040 {
00041 
00049     public function init($operand, $base = 10)
00050     {
00051         return $operand;
00052     }
00053 
00061     public function add($left_operand, $right_operand)
00062     {
00063         return bcadd($left_operand, $right_operand);
00064     }
00065 
00071     public function subtract($left_operand, $right_operand)
00072     {
00073         return bcsub($left_operand, $right_operand);
00074     }
00075 
00084     public function compare($left_operand, $right_operand)
00085     {
00086         return bccomp($left_operand, $right_operand);
00087     }
00088 
00096     public function divide($left_operand, $right_operand)
00097     {
00098         return bcdiv($left_operand, $right_operand);
00099     }
00100 
00106     public function modulus($left_operand, $modulus)
00107     {
00108         return bcmod($left_operand, $modulus);
00109     }
00110 
00116     public function multiply($left_operand, $right_operand)
00117     {
00118         return bcmul($left_operand, $right_operand);
00119     }
00120 
00126     public function pow($left_operand, $right_operand)
00127     {
00128         return bcpow($left_operand, $right_operand);
00129     }
00130 
00136     public function powmod($left_operand, $right_operand, $modulus)
00137     {
00138         return bcpowmod($left_operand, $right_operand, $modulus);
00139     }
00140 
00146     public function sqrt($operand)
00147     {
00148         return bcsqrt($operand);
00149     }
00150 
00151 
00152     public function binaryToInteger($operand)
00153     {
00154         $result = '0';
00155         while (strlen($operand)) {
00156             $ord = ord(substr($operand, 0, 1));
00157             $result = bcadd(bcmul($result, 256), $ord);
00158             $operand = substr($operand, 1);
00159         }
00160         return $result;
00161     }
00162 
00163 
00164     public function integerToBinary($operand)
00165     {
00166         $cmp = bccomp($operand, 0);
00167         $return = '';
00168         if ($cmp == 0) {
00169             return (chr(0));
00170         }
00171         while (bccomp($operand, 0) > 0) {
00172             $return = chr(bcmod($operand, 256)) . $return;
00173             $operand = bcdiv($operand, 256);
00174         }
00175         if (ord($return[0]) > 127) {
00176             $return = chr(0) . $return;
00177         }
00178         return $return;
00179     }
00180  // Prior version for referenced offset
00190 
00191 
00192     public function hexToDecimal($operand)
00193     {
00194         $return = '0';
00195         while(strlen($hex)) {
00196             $hex = hexdec(substr($operand, 0, 4));
00197             $dec = bcadd(bcmul($return, 65536), $hex);
00198             $operand = substr($operand, 4);
00199         }
00200         return $return;
00201     }
00202 
00203 }

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2