This commit is contained in:
Ata Deniz Aydın 2017-05-14 19:55:09 +03:00 committed by GitHub
parent 769375e69e
commit 8851473c6e
2 changed files with 14 additions and 3 deletions

15
modp.py
View file

@ -24,4 +24,17 @@ class ModP(int):
def _inv(self):
'Find multiplicative inverse of self in Z mod p.'
pass
# extended Euclidean algorithm
rcurr = self.p
rnext = int(self)
tcurr = 0
tnext = 1
while rnext:
q = rcurr // rnext
rcurr, rnext = rnext, rcurr - q * rnext
tcurr, tnext = tnext, tcurr - q * tnext
if rcurr != 1:
raise ValueError("%d not a unit modulo %d" % (self, self.p))
return ModP(self.p, tcurr)

View file

@ -31,8 +31,6 @@ class PAdic:
return int(self.get(32), p)
def __str__(self):
return self.get(32)
def __repr__(self):
pass
# arithmetic operations
def __add__(self, other):