예제 #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