I'm trying to write an implementation of Montgomery multiplication in Python and I need an equivalent to GMP's mpz_getlimbn()
for Python longs but I can't for the life of me seem to find one.
Any help would be greatly appreciated.
Edit
I've implemented the following but I get index out of range errors for limbs which don't occur in GMP.
def unpack(x, b):
if gmpy2:
return [long(x) for x in gmpy2.unpack(gmpy2.mpz(x), b)]
b = 2 ** b
r = []
while x:
x, temp = divmod(x, b)
r.append(temp)
return r