コード例 #1
0
ファイル: test_fingroups.py プロジェクト: vishalbelsare/mpyc
    def test_Sn(self):
        S0 = fg.SymmetricGroup(0)
        self.assertEqual(S0.degree, 0)
        self.assertEqual(S0.order, 1)
        p = S0.identity
        self.assertEqual(p^2, p)
        self.assertRaises(TypeError, operator.add, p, p)
        self.assertRaises(TypeError, operator.mul, p, p)
        self.assertRaises(TypeError, operator.mul, 1, p)

        S1 = fg.SymmetricGroup(1)
        self.assertEqual(S1.degree, 1)
        self.assertEqual(S1.order, 1)
        p = S1.identity
        self.assertEqual(p^2, p^-1)

        S3 = fg.SymmetricGroup(3)
        self.assertEqual(S3.degree, 3)
        self.assertEqual(S3.order, 6)
        self.assertEqual(S3.identity, S3([0, 1, 2]))
        p = S3([1, 2, 0])
        self.assertEqual(p^3, S3.identity)
        q = S3([1, 0, 2])
        self.assertEqual(q @ q, S3.identity)
        self.assertEqual(q, ~q)
        self.assertEqual(p @ q, S3([0, 2, 1]))
        self.assertEqual(q @ p, S3([2, 1, 0]))

        self.assertEqual({p, q, q}, {p, p, q})

        self.assertRaises(ValueError, S3, [1, 2])
        self.assertRaises(ValueError, S3, [1, 2, 3])
コード例 #2
0
ファイル: test_fingroups.py プロジェクト: vishalbelsare/mpyc
 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)
コード例 #3
0
    def test_Sn(self):
        group = fg.SymmetricGroup(5)
        a = group([3, 4, 2, 1, 0])
        b = a @ a
        secgrp = mpc.SecGrp(group)
        c = secgrp(a)
        d = a @ c
        self.assertEqual(mpc.run(mpc.output(d)), b)
        e = ~c
        f = e @ b
        self.assertEqual(mpc.run(mpc.output(f)), a)
        self.assertTrue(mpc.run(mpc.output(f == c)))

        group = fg.SymmetricGroup(11)
        secgrp = mpc.SecGrp(group)
        a = group([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0])
        secfld = mpc.SecFld(11)  # ord(a) = 11
        a7 = secgrp.repeat(a, secfld(7))
        self.assertEqual(mpc.run(mpc.output(a7)), a ^ 7)
        a7 = secgrp.repeat_public(a, secfld(7))
        self.assertEqual(mpc.run(a7), a ^ 7)
        a6 = a ^ 6
        a12 = a6 @ a6
        self.assertEqual(mpc.run(mpc.output(secgrp(a6).inverse())), a ^ 5)
        self.assertEqual(
            mpc.run(mpc.output((secgrp(a) ^ 6) @ secgrp.identity)), a6)
        self.assertEqual(mpc.run(mpc.output(secgrp.repeat(a6, secfld(2)))),
                         a12)
        self.assertEqual(
            mpc.run(mpc.output(secgrp.repeat(secgrp(a), secfld(6)))), a6)

        p = secgrp(a)
        self.assertRaises(TypeError, operator.add, p, p)
        self.assertRaises(TypeError, operator.mul, p, p)
        self.assertRaises(TypeError, operator.mul, 1, p)
        group.is_multiplicative = True
        self.assertTrue(mpc.run(mpc.output(a * p == a ^ 2)))
        group.is_multiplicative = False
        self.assertRaises(ValueError, secgrp, [0, 1, 2, 3])
コード例 #4
0
ファイル: test_fingroups.py プロジェクト: vishalbelsare/mpyc
 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)