Beispiel #1
0
    def test_Cl(self):
        Cl23 = fg.ClassGroup(Delta=-23)
        secgrp = mpc.SecGrp(Cl23)
        secint = secgrp.sectype
        g = Cl23.generator
        self.assertFalse(mpc.run(mpc.output(secgrp(g) != g)))
        self.assertEqual(mpc.run(secgrp.repeat_public(g, -secint(2))), g)
        self.assertEqual(mpc.run(mpc.output(g**secint(-2))), g)
        self.assertEqual(mpc.run(mpc.output(g * secgrp(g))), Cl23((2, -1, 3)))

        Cl227 = fg.ClassGroup(Delta=-227)  # Example 9.6.2 from Buchman&Vollmer
        secgrp = mpc.SecGrp(Cl227)
        g = Cl227((3, 1, 19))
        self.assertEqual(mpc.run(mpc.output(secgrp(g) ^ 5)), g ^ 5)

        Cl1123 = fg.ClassGroup(
            Delta=-1123)  # Example 9.7.5 from Buchman&Vollmer
        secgrp = mpc.SecGrp(Cl1123)
        self.assertEqual(Cl1123((1, 1, 281)), Cl1123.identity)
        g = Cl1123((7, 5, 41))
        self.assertEqual(mpc.run(mpc.output(secgrp(g) ^ 5)), g ^ 5)
        self.assertEqual(mpc.run(mpc.output(secgrp(g)**3)), g ^ 3)

        group = fg.ClassGroup(l=28)
        secgrp = mpc.SecGrp(group)
        g = group.generator
        a = secgrp(g) ^ 6
        self.assertEqual(mpc.run(mpc.output(a)), g ^ 6)
        self.assertEqual(mpc.run(mpc.output(a * (a ^ -1))), group.identity)
        m, z = group.encode(5)
        self.assertEqual(
            mpc.run(mpc.output(secgrp.decode(secgrp(m), secgrp(z)))), 5)

        self.assertRaises(ValueError, secgrp, [0])
Beispiel #2
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)
Beispiel #3
0
    def test_Cl(self):
        Cl3 = fg.ClassGroup()  # trivial class group D=-3 with 1 elt
        g = Cl3((1, 1, 1))
        self.assertEqual(g * (1 / g) @ g ^ 2, Cl3.identity)
        self.assertEqual({g, 1 / g, 1 / g}, {g, g, 1 / g})

        Cl23 = self.Cl23  # discriminant -23
        self.assertEqual(Cl23.order, 3)
        self.assertTrue(Cl23.is_multiplicative)
        g = Cl23.generator
        self.assertEqual(g, Cl23((2, 1, 3)))
        self.assertEqual(g * g, Cl23((2, -1)))
        self.assertEqual((g ^ 2) @ g, Cl23.identity)
        self.assertEqual(g @ g.inverse(), Cl23.identity)

        Cl227 = fg.ClassGroup(Delta=-227)  # Example 9.6.2 from Buchman&Vollmer
        self.assertEqual(Cl227.order, 5)
        self.assertEqual(Cl227((1, 1, 57)), Cl227.identity)
        g = Cl227((3, 1, 19))
        self.assertEqual(g ^ 5, Cl227.identity)

        Cl1123 = fg.ClassGroup(
            Delta=-1123)  # Example 9.7.5 from Buchman&Vollmer
        self.assertEqual(Cl1123((1, 1, 281)), Cl1123.identity)
        g = Cl1123((7, 5, 41))
        self.assertEqual(g ^ 5, Cl1123.identity)
        self.assertEqual(g ^ 3, Cl1123((17, 13, 19)))
        self.assertRaises(ValueError, Cl23, (1, 1, 2))
        self.assertRaises(ValueError, Cl23, (2, 2, 2))

        Cl_2_16 = fg.ClassGroup(l=16)
        g = Cl_2_16.generator
        a = (g ^ 10000) ^ 128
        self.assertEqual(a @ (a ^ -1), Cl_2_16.identity)

        Cl_2_32 = fg.ClassGroup(l=32)
        self.assertEqual(Cl_2_32.generator ^ 20021, Cl_2_32.identity)
        self.assertEqual(Cl_2_32.decode(*Cl_2_32.encode(24)), 24)

        self.assertRaises(ValueError, fg.ClassGroup, -13)
        self.assertRaises(ValueError, fg.ClassGroup, 13)
        self.assertRaises(ValueError, fg.ClassGroup, -12)
        self.assertRaises(ValueError, Cl23, (-2, 1, -3))
Beispiel #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)