[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
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 namespace phpseclib3\Math\BigInteger\Engines\PHP\Reductions; 15 16 use phpseclib3\Math\BigInteger\Engines\PHP\Base; 17 18 /** 19 * PHP Power Of Two Modular Exponentiation Engine 20 * 21 * @author Jim Wigginton <terrafrost@php.net> 22 */ 23 abstract class PowerOfTwo extends Base 24 { 25 /** 26 * Prepare a number for use in Montgomery Modular Reductions 27 * 28 * @param array $x 29 * @param array $n 30 * @param string $class 31 * @return array 32 */ 33 protected static function prepareReduce(array $x, array $n, $class) 34 { 35 return self::reduce($x, $n, $class); 36 } 37 38 /** 39 * Power Of Two Reduction 40 * 41 * @param array $x 42 * @param array $n 43 * @param string $class 44 * @return array 45 */ 46 protected static function reduce(array $x, array $n, $class) 47 { 48 $lhs = new $class(); 49 $lhs->value = $x; 50 $rhs = new $class(); 51 $rhs->value = $n; 52 53 $temp = new $class(); 54 $temp->value = [1]; 55 56 $result = $lhs->bitwise_and($rhs->subtract($temp)); 57 return $result->value; 58 } 59 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body