45 private const GENERATORS = [
52 [ 51961523, 89999999 ],
53 [ 519615218, 899999963 ],
54 [ 5196152444, 9000000043 ],
66 $this->offset = $config[
'offset'] ?? 0;
67 $this->hasGmp = extension_loaded(
'gmp' );
68 $this->hasBcm = extension_loaded(
'bcmath' );
69 if ( !$this->hasGmp && !$this->hasBcm ) {
70 throw new \MWException( __CLASS__ .
' requires the bcmath or gmp extension' );
76 return (
string)$index;
78 $offset = $this->offset;
79 foreach ( self::GENERATORS as [ $g, $p ] ) {
80 if ( $index - $offset < $p ) {
81 return (
string)( $offset + $this->powmod( $g, $index - $offset, $p ) );
85 throw new \MWException( __METHOD__ .
": The index $index is too large" );
88 private function powmod( $num, $exponent, $modulus ) {
89 if ( $this->hasGmp ) {
90 return \gmp_intval( \gmp_powm( $num, $exponent, $modulus ) );
91 } elseif ( $this->hasBcm ) {
92 return (
int)\bcpowmod( (
string)$num, (
string)$exponent, (
string)$modulus );
94 throw new \MWException( __CLASS__ .
' requires the bcmath or gmp extension' );