Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # b^n (mod m)
- def modExp(b, n, m):
- binary = format(n, "0b")
- result = 1
- # Update b if it is more than or equal to m
- b = b % m
- if (b == 0):
- return 0
- binary = str(binary)[::-1]
- for i in range(len(binary)):
- if (binary[i] == "1"):
- result = (result * b) % m
- b = (b * b) % m
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement