Skip to content

Instantly share code, notes, and snippets.

@tqbf
Created August 3, 2011 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tqbf/1123831 to your computer and use it in GitHub Desktop.
Save tqbf/1123831 to your computer and use it in GitHub Desktop.
n = random.randrange(m)
def modpow(a, n, m):
r = 1
while n > 0:
if n & 1 == 1:
r = (r * a) % m
n = n >> 1
a = (a * a) % m
n = rand(m)
def modpow(a, n, m)
  r = 1
  loop do
    r = r * a % m if n[0] == 1
    n >>= 1
    return r if n == 0
    a = a * a % m
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment