Ejemplo n.º 1
0
    def sec_inverse(self):
        if isinstance(self.value, complex):
            return complex_truediv_algorithm(complex(1), self.value,
                                             self.__class__)

        gcd, x, y = extended_euclidean_algorithm(self.value, self.P)
        assert (self.value * x + self.P * y) == gcd
        if gcd != 1:
            # Either n is 0, or p is not prime number
            raise ValueError('{} has no multiplicate inverse '
                             'modulo {}'.format(self.value, self.P))
        return self.__class__(x % self.P)
Ejemplo n.º 2
0
 def __truediv__(self, g: 'Field') -> 'Field':
     if isinstance(g.id, complex):
         return complex_truediv_algorithm(complex(1), self.id, self.type)
     return self.sec_op(g.sec_inverse())
Ejemplo n.º 3
0
 def __truediv__(self, g: 'Group') -> 'Group':
     if isinstance(g.value, complex):
         return complex_truediv_algorithm(complex(1), self.value,
                                          self.__class__)
     return self.sec_op(g.sec_inverse())