fast-mod-exp
Version:
Fast modular exponentiation function, for numbers and bigints.
36 lines (25 loc) • 591 B
Markdown
for numbers and bigints.
```sh
npm install fast-mod-exp
```
This is equivalent to doing `( a ** b ) % n`, assuming bigints or infinite precision, but way faster in many cases.
```ts
import fme from 'fast-mod-exp';
{ // It works with numbers
const a = 123;
const b = 23;
const n = 531;
const result = fme ( a, b, n ); // => 171
}
{ // It works with bigints also
const a = 123n;
const b = 23n;
const n = 531n;
const result = fme ( a, b, n ); // => 171n
}
```
MIT © Fabio Spampinato
Fast modular exponentiation function,