Example #1
0
    def test_QR_SG(self):
        for group in self.QR11, self.SG11:
            self.assertEqual(group.order, 5)
            self.assertTrue(group.is_cyclic)
            self.assertEqual(group.identity, group(1))
            a = group(3)
            self.assertEqual(a^5, group.identity)
            b = group(4)
            self.assertEqual(b^5, group.identity)
            self.assertEqual(a * b, group.identity)
            self.assertEqual(1/a, b)
            self.assertEqual(a / b, a**2)
            self.assertRaises(TypeError, operator.truediv, 2, a)
            self.assertRaises(TypeError, operator.add, a, b)
            self.assertRaises(TypeError, operator.neg, a)
            self.assertRaises(TypeError, operator.sub, a, b)
            self.assertRaises(TypeError, group, 1.0)
            self.assertRaises(ValueError, group, 0)
            self.assertRaises(ValueError, group, 2)

            self.assertEqual({a, b, b}, {a, a, b})

        self.assertRaises(ValueError, fg.QuadraticResidues, 2)
        QR_768 = fg.QuadraticResidues(l=768)
        self.assertEqual(QR_768.decode(*QR_768.encode(42)), 42)
        SG = fg.SchnorrGroup(q=2**31 - 1)
        self.assertEqual(SG.decode(*SG.encode(42)), 42)
Example #2
0
    def test_QR_SG(self):
        for group in fg.QuadraticResidues(l=768), fg.SchnorrGroup(l=768):
            secgrp = mpc.SecGrp(group)
            g = group.generator
            g2 = mpc.run(mpc.output(secgrp(g) * g))
            self.assertEqual(int(g), int(group.identity * g))
            self.assertFalse(
                mpc.run(mpc.output(secgrp(g) / g != group.identity)))
            self.assertTrue(mpc.run(mpc.output(g * secgrp(g) == g2)))
            secfld = mpc.SecFld(modulus=secgrp.group.order)
            self.assertEqual(mpc.run(mpc.output(secgrp.repeat(g, -secfld(2)))),
                             1 / g2)
            self.assertEqual(mpc.run(mpc.output(secgrp.repeat(secgrp(g), 2))),
                             g2)
            m, z = group.encode(15)
            self.assertEqual(
                mpc.run(mpc.output(secgrp.decode(secgrp(m), secgrp(z)))), 15)
            h = secgrp.if_else(secgrp.sectype(0), g, secgrp(g2))
            self.assertEqual(mpc.run(mpc.output(h)), g2)

            a = secgrp(g)
            self.assertRaises(TypeError, operator.truediv, 2, a)
            self.assertRaises(TypeError, operator.add, a, a)
            self.assertRaises(TypeError, operator.add, g, a)
            self.assertRaises(TypeError, operator.neg, a)
            self.assertRaises(TypeError, operator.sub, a, a)
            self.assertRaises(TypeError, operator.sub, g, a)
Example #3
0
 def test_group_caching(self):
     S3_cached = fg.SymmetricGroup(3)
     self.assertEqual(self.S3, S3_cached)
     self.assertEqual(self.S3(), S3_cached())
     QR11_cached = fg.QuadraticResidues(l=4)
     self.assertEqual(self.QR11, QR11_cached)
     Cl23_cached = fg.ClassGroup(Delta=-23)
     self.assertEqual(self.Cl23, Cl23_cached)
     self.assertEqual(self.Cl23(), Cl23_cached())
     Cl23_cached = fg.ClassGroup(l=5)
     self.assertEqual(self.Cl23, Cl23_cached)
Example #4
0
 def setUp(self):
     self.S3 = fg.SymmetricGroup(3)
     self.QR11 = fg.QuadraticResidues(11)
     self.SG11 = fg.SchnorrGroup(11, 5, 4)
     self.Cl23 = fg.ClassGroup(Delta=-23)