示例#1
0
文件: field.py 项目: timleslie/pygeom
    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
示例#2
0
文件: field.py 项目: marchon/pygeom
    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
示例#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