modular exponentiation in Python implementation

#53
by LauBen - opened

In the context of cryptography, I asked "Is the Pohlig Hellman algorithm for the discrete logarithm problem exponential in time?". The answer is seems good.
However when I ask for a Python implementation, it seems quite bad. As an illustration, a modular exponentiation function that is acceptable is provided, but there is a much faster exponentiation algorithm, it is the basics. Even worse, the latter is a builtin function!
Here's HF chat function:

Powers together using multiplication and addition operations only

def powmod(base, exponent, modulus):
result = 1
while exponent > 0:
result = ((result * base) % modulus)
exponent -= 1
return result
More generally, it seems that the Python implementations are not very reliable.

Sign up or log in to comment