| 62 | } |
| 63 | |
| 64 | BigUint math::Powmod(BigUint n, BigUint e, BigUint m) { |
| 65 | if (e == 1) return n % m; |
| 66 | if (e == 0) return 1; |
| 67 | |
| 68 | if ((e & 1) == 1) { |
| 69 | // y = n ^ e mod m |
| 70 | // y = ((n mod m) * ((n ^ (e-1) mod m))) mod m |
| 71 | return ((n % m) * (Powmod(n, e - 1, m))) % m; |
| 72 | } |
| 73 | BigUint tmp = Powmod(n, e / 2, m); |
| 74 | return (tmp * tmp) % m; |
| 75 | } |
| 76 | |
| 77 | BigUint math::Invert(BigUint a, BigUint n) { |
| 78 | BigUint result; |
nothing calls this directly
no outgoing calls
no test coverage detected