I'm trying to implement RSA encryption/decryption (a simple implementation of course, so there's no need for nitpicking) and it seems like the numbers (i.e. the keys) are fine, yet the final result is wrong.
Here's the problematic function:
def square_and_mult(base, k, mod):
b = 1
for ki in reversed(k):
if ki == '0':
b = (b**2) % mod
else:
b = ((b**2) * base) % mod
return b