Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Zend_Crypt_Math_BigInteger_Gmp Class Reference
Inheritance diagram for Zend_Crypt_Math_BigInteger_Gmp:
Zend_Crypt_Math_BigInteger_Interface

Public Member Functions

 init ($operand, $base=10)
 
 add ($left_operand, $right_operand)
 
 subtract ($left_operand, $right_operand)
 
 compare ($left_operand, $right_operand)
 
 divide ($left_operand, $right_operand)
 
 modulus ($left_operand, $modulus)
 
 multiply ($left_operand, $right_operand)
 
 pow ($left_operand, $right_operand)
 
 powmod ($left_operand, $right_operand, $modulus)
 
 sqrt ($operand)
 
 binaryToInteger ($operand)
 
 integerToBinary ($operand)
 
 hexToDecimal ($operand)
 

Detailed Description

Definition at line 39 of file Gmp.php.

Member Function Documentation

◆ add()

add (   $left_operand,
  $right_operand 
)

Adds two arbitrary precision numbers

Parameters
resource$left_operand
resource$right_operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 60 of file Gmp.php.

61  {
62  $result = gmp_add($left_operand, $right_operand);
63  return gmp_strval($result);
64  }

◆ binaryToInteger()

binaryToInteger (   $operand)
Parameters
string$operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 178 of file Gmp.php.

179  {
180  $result = '0';
181  while (strlen($operand)) {
182  $ord = ord(substr($operand, 0, 1));
183  $result = gmp_add(gmp_mul($result, 256), $ord);
184  $operand = substr($operand, 1);
185  }
186  return gmp_strval($result);
187  }

◆ compare()

compare (   $left_operand,
  $right_operand 
)

Compare two big integers and returns result as an integer where 0 means both are identical, 1 that left_operand is larger, or -1 that right_operand is larger.

Parameters
resource$left_operand
resource$right_operand
Returns
int

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 88 of file Gmp.php.

89  {
90  $result = gmp_cmp($left_operand, $right_operand);
91  return gmp_strval($result);
92  }

◆ divide()

divide (   $left_operand,
  $right_operand 
)

Divide two big integers and return result or NULL if the denominator is zero.

Parameters
resource$left_operand
resource$right_operand
Returns
string|null

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 102 of file Gmp.php.

103  {
104  $result = gmp_div($left_operand, $right_operand);
105  return gmp_strval($result);
106  }

◆ hexToDecimal()

hexToDecimal (   $operand)
Parameters
string$operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 209 of file Gmp.php.

210  {
211  $return = '0';
212  while(strlen($hex)) {
213  $hex = hexdec(substr($operand, 0, 4));
214  $dec = gmp_add(gmp_mul($return, 65536), $hex);
215  $operand = substr($operand, 4);
216  }
217  return $return;
218  }

◆ init()

init (   $operand,
  $base = 10 
)

Initialise a big integer into an extension specific type.

Parameters
string$operand
int$base
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 48 of file Gmp.php.

49  {
50  return $operand;
51  }

◆ integerToBinary()

integerToBinary (   $operand)
Parameters
resource$operandGMP number resource
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 193 of file Gmp.php.

194  {
195  $bigInt = gmp_strval($operand, 16);
196  if (strlen($bigInt) % 2 != 0) {
197  $bigInt = '0' . $bigInt;
198  } else if ($bigInt[0] > '7') {
199  $bigInt = '00' . $bigInt;
200  }
201  $return = pack("H*", $bigInt);
202  return $return;
203  }

◆ modulus()

modulus (   $left_operand,
  $modulus 
)

Modulo operation

Parameters
resource$left_operand
resource$modulus

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 116 of file Gmp.php.

117  {
118  $result = gmp_mod($left_operand, $modulus);
119  return gmp_strval($result);
120  }

◆ multiply()

multiply (   $left_operand,
  $right_operand 
)

Multiply numbers

Parameters
resource$left_operand
resource$right_operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 129 of file Gmp.php.

130  {
131  $result = gmp_mul($left_operand, $right_operand);
132  return gmp_strval($result);
133  }

◆ pow()

pow (   $left_operand,
  $right_operand 
)

Raise number into power

Parameters
resource$left_operand
int$right_operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 142 of file Gmp.php.

143  {
144  $result = gmp_pow($left_operand, $right_operand);
145  return gmp_strval($result);
146  }

◆ powmod()

powmod (   $left_operand,
  $right_operand,
  $modulus 
)

Raise number into power with modulo

Parameters
resource$left_operand
resource$right_operand
resource$modulus
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 156 of file Gmp.php.

157  {
158  $result = gmp_powm($left_operand, $right_operand, $modulus);
159  return gmp_strval($result);
160  }

◆ sqrt()

sqrt (   $operand)

Calculate square root

Parameters
$operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 168 of file Gmp.php.

169  {
170  $result = gmp_sqrt($operand);
171  return gmp_strval($result);
172  }

◆ subtract()

subtract (   $left_operand,
  $right_operand 
)

Subtract numbers

Parameters
resource$left_operand
resource$right_operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 73 of file Gmp.php.

74  {
75  $result = gmp_sub($left_operand, $right_operand);
76  return gmp_strval($result);
77  }

The documentation for this class was generated from the following file: