其余两个待补充
#!/usr/dev/python
#-*- coding:utf-8 -*-
'''
Extended Euclidean algorithm(a,b)
code by ShaNgZ
algorithm from <cryptography theory and pratice,third editon>
2019_01_09
'''
a = input("a=")
b = input("b=")
s0 = 0
s = 1
t0 = 0
t = 1
q = a/b
r = a%b
# Ri = Si*R0 + Ti*R1
def euclidean_algorithen():
pass
def extended_euclidean():
global a,b,s0,s,t0,t,q,r
ex_a = a
ex_b = b
ex_s0 = s0
ex_s = 1
ex_t0 = 0
ex_t = 1
ex_q = q
ex_r = r
while(ex_r>0):
temp = ex_t0-ex_q*ex_t
ex_t0 = ex_t
ex_t = temp
temp = ex_s0-ex_q*ex_s
ex_s0 = ex_s
ex_s = temp
ex_a = ex_b
ex_b = ex_r
ex_q = ex_a/ex_b
ex_r = ex_a%ex_b
ex_r = ex_b
print "exr_gcd(%d,%d) = " % (a,b) + str(ex_r)
if ex_r == 1:
print "inverse(%d) mod %d = %d" % (a,b,ex_s)
#comment: r=gcd(a,b) and sa+tb=r
def multiplicative_inverse():
pass
if __name__ == '__main__':
extended_euclidean()