| Total Complexity | 6 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class ModularArithmetic |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var GmpMathInterface |
||
| 9 | */ |
||
| 10 | private $adapter; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var \GMP |
||
| 14 | */ |
||
| 15 | private $modulus; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param GmpMathInterface $adapter |
||
| 19 | * @param \GMP $modulus |
||
| 20 | */ |
||
| 21 | public function __construct(GmpMathInterface $adapter, \GMP $modulus) |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param \GMP $augend |
||
| 29 | * @param \GMP $addend |
||
| 30 | * @return \GMP |
||
| 31 | */ |
||
| 32 | public function add(\GMP $augend, \GMP $addend): \GMP |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param \GMP $minuend |
||
| 39 | * @param \GMP $subtrahend |
||
| 40 | * @return \GMP |
||
| 41 | */ |
||
| 42 | public function sub(\GMP $minuend, \GMP $subtrahend): \GMP |
||
| 43 | { |
||
| 44 | return $this->adapter->mod($this->adapter->sub($minuend, $subtrahend), $this->modulus); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param \GMP $multiplier |
||
| 49 | * @param \GMP $muliplicand |
||
| 50 | * @return \GMP |
||
| 51 | */ |
||
| 52 | public function mul(\GMP $multiplier, \GMP $muliplicand): \GMP |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param \GMP $dividend |
||
| 59 | * @param \GMP $divisor |
||
| 60 | * @return \GMP |
||
| 61 | */ |
||
| 62 | public function div(\GMP $dividend, \GMP $divisor): \GMP |
||
| 63 | { |
||
| 64 | return $this->mul($dividend, $this->adapter->inverseMod($divisor, $this->modulus)); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param \GMP $base |
||
| 69 | * @param \GMP $exponent |
||
| 70 | * @return \GMP |
||
| 71 | */ |
||
| 72 | public function pow(\GMP $base, \GMP $exponent): \GMP |
||
| 75 | } |
||
| 76 | } |
||
| 77 |