Skip to content

Instantly share code, notes, and snippets.

@hzshang
Created November 14, 2017 15:04
Show Gist options
  • Save hzshang/616c51c25096aa33cce6d4051aad350b to your computer and use it in GitHub Desktop.
Save hzshang/616c51c25096aa33cce6d4051aad350b to your computer and use it in GitHub Desktop.
mod inverse for RSA
def ext_Euclid(n,m):
if (m == 0):
return 1, 0
else:
x, y = ext_Euclid(m, n%m)
x, y = y, (x -(n//m)*y)
return x, y
def mod_inverse(e,n):
x,y=ext_Euclid(e,n)
return (x+n)%n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment