Add AbstractAlgebra notes ch18-ch26

This commit is contained in:
2022-02-26 18:38:53 +01:00
parent e69a4b792f
commit 1e98a56325
6 changed files with 120 additions and 10 deletions

View File

@@ -32,6 +32,12 @@ def gcd(a, b):
return g*b
def gcd_recursive(a, b):
if mod(a, b)==0:
return b
return gcd_recursive(b, mod(a,b))
# Extended Euclidean algorithm
# Inputs: a, b
# Outputs: r, x, y, such that r = gcd(a, b) = x*a + y*b
@@ -54,6 +60,13 @@ def egcd(a, b):
return d, x, y
def egcd_recursive(a, b):
if b==0:
return a, 1, 0
g, x, y = egcd_recursive(b, a%b)
return g, y, x - (a//b) * y
# Inverse modulo N, using the Extended Euclidean algorithm
def inv_mod(a, N):
g, x, y = egcd(a, N)