def test_inv(self): e = FieldElement(0, self.p) g = e.inverse() self.assertEqual(g, None) f = FieldElement(1, self.p) g = f.inverse() self.assertEqual(int(g), 1) for _ in range(0, 10000): e = FieldElement.urandom(self.p) f = e.inverse() if f is None: self.assertEqual(int(e), 0) else: g = e * f self.assertEqual(int(g), 1)
def test_sqrt(self): e = FieldElement(0, self.p) g = e.sqrt() self.assertEqual(g, None) f = FieldElement(1, self.p) g = f.inverse() self.assertEqual(int(g * g), 1) self.assertEqual(int(g * g), f) for _ in range(0, 10000): e = FieldElement.urandom(self.p) f = e.sqrt() if f is not None: g = f * f self.assertEqual(int(g), int(e)) self.assertEqual(g, e)