Académique Documents
Professionnel Documents
Culture Documents
Exponention
Exponention
ac = 1
apo = a
while e > 0;
if e & 1:
ac = (ac * apo ) % n
e= e >> 1
return ac
print(apmod(5,12,197))
print(pow(5,12,197))
Algorithme
Résolution d’équation modulaire linéaire
1. (d.x’.y’) = EXTENDED-EUCLID(a,b,n)
2. If d| b
a. X0 = x’(b/d)mod n
b. For I = 0 to d-1
i. Print (x0+i(n/d)) mod n
3. Else print “no solutions”
Implementation
def euclide_etendu(c,d):
if c == 0
return d,0,1
gcd,x1,y1 = euclide_etendu(d%c,c)
x=y1 -(d//a)*x1
y=x1
return gcd,x,y
def modulo(x,N);
return (x % N + N) % N;
def rm(c,d,n)
gcd,x1,y1 = euclide_etendu(c,n)
if d % gcd == 0:
x0=modulo(x1*(d/gcd),n)
i=0
res=modulo(x0 + i * (n / gcd),n)
i= i + 1
else:
print("pas de solution")
rm(30,12,4)