Rev 874 | Rev 1101 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 874 | Rev 1042 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | /** |
3 | /** |
4 | * Base BigInteger Engine |
4 | * Base BigInteger Engine |
5 | * |
5 | * |
6 | * PHP version 5 and 7 |
6 | * PHP version 5 and 7 |
7 | * |
7 | * |
8 | * @category Math |
- | |
9 | * @package BigInteger |
- | |
10 | * @author Jim Wigginton <terrafrost@php.net> |
8 | * @author Jim Wigginton <terrafrost@php.net> |
11 | * @copyright 2017 Jim Wigginton |
9 | * @copyright 2017 Jim Wigginton |
12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
10 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
13 | * @link http://pear.php.net/package/Math_BigInteger |
11 | * @link http://pear.php.net/package/Math_BigInteger |
14 | */ |
12 | */ |
15 | 13 | ||
16 | namespace phpseclib3\Math\BigInteger\Engines; |
14 | namespace phpseclib3\Math\BigInteger\Engines; |
17 | 15 | ||
18 | use ParagonIE\ConstantTime\Hex; |
- | |
19 | use phpseclib3\Common\Functions\Strings; |
16 | use phpseclib3\Common\Functions\Strings; |
20 | use phpseclib3\Crypt\Random; |
17 | use phpseclib3\Crypt\Random; |
21 | use phpseclib3\Exception\BadConfigurationException; |
18 | use phpseclib3\Exception\BadConfigurationException; |
22 | use phpseclib3\Math\BigInteger; |
19 | use phpseclib3\Math\BigInteger; |
23 | 20 | ||
24 | /** |
21 | /** |
25 | * Base Engine. |
22 | * Base Engine. |
26 | * |
23 | * |
27 | * @package Engine |
- | |
28 | * @author Jim Wigginton <terrafrost@php.net> |
24 | * @author Jim Wigginton <terrafrost@php.net> |
29 | * @access public |
- | |
30 | */ |
25 | */ |
31 | abstract class Engine implements \JsonSerializable |
26 | abstract class Engine implements \JsonSerializable |
32 | { |
27 | { |
33 | /* final protected */ const PRIMES = [ |
28 | /* final protected */ const PRIMES = [ |
34 | 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, |
29 | 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, |
Line 174... | Line 169... | ||
174 | $x = preg_replace('#^(?:0x)?([A-Fa-f0-9]*).*#', '$1', $x); |
169 | $x = preg_replace('#^(?:0x)?([A-Fa-f0-9]*).*#', '$1', $x); |
175 | 170 | ||
176 | $is_negative = false; |
171 | $is_negative = false; |
177 | if ($base < 0 && hexdec($x[0]) >= 8) { |
172 | if ($base < 0 && hexdec($x[0]) >= 8) { |
178 | $this->is_negative = $is_negative = true; |
173 | $this->is_negative = $is_negative = true; |
179 | $x = Hex::encode(~Hex::decode($x)); |
174 | $x = Strings::bin2hex(~Strings::hex2bin($x)); |
180 | } |
175 | } |
181 | 176 | ||
182 | $this->value = $x; |
177 | $this->value = $x; |
183 | $this->initialize($base); |
178 | $this->initialize($base); |
184 | 179 | ||
Line 272... | Line 267... | ||
272 | * @param bool $twos_compliment |
267 | * @param bool $twos_compliment |
273 | * @return string |
268 | * @return string |
274 | */ |
269 | */ |
275 | public function toHex($twos_compliment = false) |
270 | public function toHex($twos_compliment = false) |
276 | { |
271 | { |
277 | return Hex::encode($this->toBytes($twos_compliment)); |
272 | return Strings::bin2hex($this->toBytes($twos_compliment)); |
278 | } |
273 | } |
279 | 274 | ||
280 | /** |
275 | /** |
281 | * Converts a BigInteger to a bit string (eg. base-2). |
276 | * Converts a BigInteger to a bit string (eg. base-2). |
282 | * |
277 | * |