Beispiel #1
0
    def sqrt(self):
        """
        The square root of the number in the field.

        Returns the value a \in F such that a*a = x.

        If no such a exists, raises ValueError.
        """
        if not self.is_square():
            raise ValueError, "This number is not a square! (%s)" % str(self)
        a = self.__class__(shanks_tonelli(self.value, self._base))
        assert a * a == self
        return a
Beispiel #2
0
    def sqrt(self):
        """
        The square root of the number in the field.

        Returns the value a \in F such that a*a = x.

        If no such a exists, raises ValueError.
        """
        if not self.is_square():
            raise ValueError, "This number is not a square! (%s)" % str(self)
        a = self.__class__(shanks_tonelli(self.value, self._base))
        assert a*a == self
        return a
Beispiel #3
0
def test_shanks():
    p = 37
    for i in range(1, p):
        n = i*i % p
        st = shanks_tonelli(n, p)
        assert st*st % p == n