backup
/
src
/
JetBackup
/
3rdparty
/
phpseclib3
/
Math
/
BigInteger
/
Engines
/
PHP
/
Reductions
/
PowerOfTwo.php
backup
/
src
/
JetBackup
/
3rdparty
/
phpseclib3
/
Math
/
BigInteger
/
Engines
/
PHP
/
Reductions
Last commit date
.htaccess
1 year ago
Barrett.php
1 year ago
Classic.php
1 year ago
EvalBarrett.php
1 year ago
Montgomery.php
1 year ago
MontgomeryMult.php
1 year ago
PowerOfTwo.php
1 year ago
index.html
1 year ago
web.config
1 year ago
PowerOfTwo.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * PHP Power of Two Modular Exponentiation Engine |
| 5 | * |
| 6 | * PHP version 5 and 7 |
| 7 | * |
| 8 | * @author Jim Wigginton <terrafrost@php.net> |
| 9 | * @copyright 2017 Jim Wigginton |
| 10 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
| 11 | * @link http://pear.php.net/package/Math_BigInteger |
| 12 | */ |
| 13 | |
| 14 | declare(strict_types=1); |
| 15 | |
| 16 | namespace phpseclib3\Math\BigInteger\Engines\PHP\Reductions; |
| 17 | |
| 18 | use phpseclib3\Math\BigInteger\Engines\PHP\Base; |
| 19 | |
| 20 | /** |
| 21 | * PHP Power Of Two Modular Exponentiation Engine |
| 22 | * |
| 23 | * @author Jim Wigginton <terrafrost@php.net> |
| 24 | */ |
| 25 | abstract class PowerOfTwo extends Base |
| 26 | { |
| 27 | /** |
| 28 | * Prepare a number for use in Montgomery Modular Reductions |
| 29 | */ |
| 30 | protected static function prepareReduce(array $x, array $n, string $class): array |
| 31 | { |
| 32 | return self::reduce($x, $n, $class); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Power Of Two Reduction |
| 37 | */ |
| 38 | protected static function reduce(array $x, array $n, string $class): array |
| 39 | { |
| 40 | $lhs = new $class(); |
| 41 | $lhs->value = $x; |
| 42 | $rhs = new $class(); |
| 43 | $rhs->value = $n; |
| 44 | |
| 45 | $temp = new $class(); |
| 46 | $temp->value = [1]; |
| 47 | |
| 48 | $result = $lhs->bitwise_and($rhs->subtract($temp)); |
| 49 | return $result->value; |
| 50 | } |
| 51 | } |
| 52 |