Last active
November 18, 2022 14:16
-
-
Save Hermann-SW/aefd972ef795347bd5cc7ec4557a769f to your computer and use it in GitHub Desktop.
bc equivalent to gmp powm() "power mod" function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define powm_(a, e, n) { | |
if (e==1) return a%n | |
p = powm_(a, e/2, n) | |
if (e%2==0) { return p*p%n } else { return a*p*p%n } | |
} | |
define powm(a, e, n) { | |
if (e==0) return 1 | |
return powm_(a, e, n) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fermat little theorem 100-digit number example (RSA-100):
https://en.wikipedia.org/wiki/RSA_numbers#RSA-100