1

can someone please explain to me what's the role of montgomery reduction algorithm and how to implement it in python. I wrote the code below to calculate a*b mod m but it doesn't seem to work well.

def montgomery(a,b,m):

bin_m=format(m,'b')
R=pow(2,len(bin_m))

a_prim= a (R % m) b_prim= b (R % m)

reverse_R=euc(R,m)

if inverse_R<0: inverse_R+=m

c_prim=(a_primb_prim)reverse_R result=c_prim*reverse_R

return print(result)

meran_kud
  • 11
  • 2

0 Answers0