Skip to content

Instantly share code, notes, and snippets.

@bl4ckbo7
Last active December 10, 2020 16:08
Show Gist options
  • Save bl4ckbo7/37fc801b48d4e4b9569b22f893c69248 to your computer and use it in GitHub Desktop.
Save bl4ckbo7/37fc801b48d4e4b9569b22f893c69248 to your computer and use it in GitHub Desktop.
#Finding Bezout's Identities using Inverse modulo algorithm - PoC
#let gcd(n,e)
#from ex + by = 1
#x = e^(-1) mod n
#Author: bl4ckbo7
#!/usr/bin/env python3
e = eval(input("Enter the value of a: "))
n = eval(input("Enter the value of b: "))
d = eval(input("Enter the value of gcd: "))
x, y, mod, d, e, n = 0, 0, 0, d//d, e//d, n//d
while mod != 1:
x+=1
print( str(mod) + " = {0} * {1} % {2} ".format(e, x, n))
mod = (e * x) % n
print("-"*50)
print("x = {0}, y = {1}".format(x, (d - (e * x)) // n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment