Auth_OpenID_MathLibrary Klassenreferenz

Basisklasse für Auth_OpenID_BcMathWrapper und Auth_OpenID_GmpMathWrapper.


Öffentliche Methoden

 longToBinary ($long)
 binaryToLong ($str)
 base64ToLong ($str)
 longToBase64 ($str)
 rand ($stop)


Ausführliche Beschreibung

Definiert in Zeile 33 der Datei BigMath.php.


Dokumentation der Elementfunktionen

base64ToLong ( str  ) 

Definiert in Zeile 112 der Datei BigMath.php.

00113     {
00114         $b64 = base64_decode($str);
00115 
00116         if ($b64 === false) {
00117             return false;
00118         }
00119 
00120         return $this->binaryToLong($b64);
00121     }

binaryToLong ( str  ) 

Given a binary string, returns the binary string converted to a long number.

Parameter:
string $binary The binary version of a long number, probably as a result of calling longToBinary
Rückgabe:
integer $long The long number equivalent of the binary string $str

Definiert in Zeile 86 der Datei BigMath.php.

00087     {
00088         if ($str === null) {
00089             return null;
00090         }
00091 
00092         // Use array_merge to return a zero-indexed array instead of a
00093         // one-indexed array.
00094         $bytes = array_merge(unpack('C*', $str));
00095 
00096         $n = $this->init(0);
00097 
00098         if ($bytes && ($bytes[0] > 127)) {
00099             trigger_error("bytesToNum works only for positive integers.",
00100                           E_USER_WARNING);
00101             return null;
00102         }
00103 
00104         foreach ($bytes as $byte) {
00105             $n = $this->mul($n, pow(2, 8));
00106             $n = $this->add($n, $byte);
00107         }
00108 
00109         return $n;
00110     }

longToBase64 ( str  ) 

Definiert in Zeile 123 der Datei BigMath.php.

00124     {
00125         return base64_encode($this->longToBinary($str));
00126     }

longToBinary ( long  ) 

Given a long integer, returns the number converted to a binary string. This function accepts long integer values of arbitrary magnitude and uses the local large-number math library when available.

Parameter:
integer $long The long number (can be a normal PHP integer or a number created by one of the available long number libraries)
Rückgabe:
string $binary The binary version of $long

Definiert in Zeile 45 der Datei BigMath.php.

00046     {
00047         $cmp = $this->cmp($long, 0);
00048         if ($cmp < 0) {
00049             $msg = __FUNCTION__ . " takes only positive integers.";
00050             trigger_error($msg, E_USER_ERROR);
00051             return null;
00052         }
00053 
00054         if ($cmp == 0) {
00055             return "\x00";
00056         }
00057 
00058         $bytes = array();
00059 
00060         while ($this->cmp($long, 0) > 0) {
00061             array_unshift($bytes, $this->mod($long, 256));
00062             $long = $this->div($long, pow(2, 8));
00063         }
00064 
00065         if ($bytes && ($bytes[0] > 127)) {
00066             array_unshift($bytes, 0);
00067         }
00068 
00069         $string = '';
00070         foreach ($bytes as $byte) {
00071             $string .= pack('C', $byte);
00072         }
00073 
00074         return $string;
00075     }

rand ( stop  ) 

Returns a random number in the specified range. This function accepts $start, $stop, and $step values of arbitrary magnitude and will utilize the local large-number math library when available.

Parameter:
integer $start The start of the range, or the minimum random number to return
integer $stop The end of the range, or the maximum random number to return
integer $step The step size, such that $result - ($step * N) = $start for some N
Rückgabe:
integer $result The resulting randomly-generated number

Definiert in Zeile 142 der Datei BigMath.php.

00143     {
00144         static $duplicate_cache = array();
00145 
00146         // Used as the key for the duplicate cache
00147         $rbytes = $this->longToBinary($stop);
00148 
00149         if (array_key_exists($rbytes, $duplicate_cache)) {
00150             list($duplicate, $nbytes) = $duplicate_cache[$rbytes];
00151         } else {
00152             if ($rbytes[0] == "\x00") {
00153                 $nbytes = Auth_OpenID::bytes($rbytes) - 1;
00154             } else {
00155                 $nbytes = Auth_OpenID::bytes($rbytes);
00156             }
00157 
00158             $mxrand = $this->pow(256, $nbytes);
00159 
00160             // If we get a number less than this, then it is in the
00161             // duplicated range.
00162             $duplicate = $this->mod($mxrand, $stop);
00163 
00164             if (count($duplicate_cache) > 10) {
00165                 $duplicate_cache = array();
00166             }
00167 
00168             $duplicate_cache[$rbytes] = array($duplicate, $nbytes);
00169         }
00170 
00171         do {
00172             $bytes = "\x00" . Auth_OpenID_CryptUtil::getBytes($nbytes);
00173             $n = $this->binaryToLong($bytes);
00174             // Keep looping if this value is in the low duplicated range
00175         } while ($this->cmp($n, $duplicate) < 0);
00176 
00177         return $this->mod($n, $stop);
00178     }


Die Dokumentation für diese Klasse wurde erzeugt aufgrund der Datei:
Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved.
MyOOS [Shopsystem] is Free Software released under the GNU/GPL License.

Webmaster: info@r23.de (Impressum)
doxygen