Top Level Namespace
Defined Under Namespace
Instance Method Summary collapse
-
#exponent_mod(base, exponent, modulus) ⇒ Object
Thanks Bruce Schneier for this gem.
Instance Method Details
#exponent_mod(base, exponent, modulus) ⇒ Object
Thanks Bruce Schneier for this gem
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/better_prime/mr_prime.rb', line 2 def exponent_mod(base,exponent,modulus) result = 1; while(exponent > 0) if ((exponent & 1) == 1) result = (result * base) % modulus; end exponent >>= 1; base = (base * base) % modulus; end return result; end |