Ejemplo n.º 1
0
 def testRsub(self):
     # Fp - Fq
     s = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(1, 1)], self.F3), self.F81)
     result = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(0, 1), (1, 2)], self.F3), self.F81)
     self.assertEqual(result, self.F3.one - s)
     # Z -Fq
     self.assertEqual(result, 1 - s)
Ejemplo n.º 2
0
    def setUp(self):
        """
	create two different Fq's.
	"""
        self.F2 = FinitePrimeField.getInstance(2)
        f = FinitePrimeFieldPolynomial([(0, 1), (5, 1), (6, 1)], self.F2)
        self.F64 = FiniteExtendedField(2, f)
        self.F3 = FinitePrimeField.getInstance(3)
        f = FinitePrimeFieldPolynomial(enumerate([1, 2, 1, 2, 1]), self.F3)
        self.F81 = FiniteExtendedField(3, f)
Ejemplo n.º 3
0
 def testAdd(self):
     s = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(1, 1)], self.F3), self.F81)
     t = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(0, 1), (1, 1)], self.F3), self.F81)
     result = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(0, 1), (1, 2)], self.F3), self.F81)
     self.assertEqual(result, s + t)
     self.assertEqual(t, s + self.F81.one)
     self.assertEqual(t, s + self.F3.one)
Ejemplo n.º 4
0
 def testSub(self):
     s = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(1, 1)], self.F3), self.F81)
     t = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(0, 1), (1, 1)], self.F3), self.F81)
     result = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(0, 2)], self.F3), self.F81)
     tluser = FiniteExtendedFieldElement(
         FinitePrimeFieldPolynomial([(0, 1)], self.F3), self.F81)
     self.assertEqual(result, s - t)
     self.assertEqual(tluser, t - s)
     self.assertEqual(self.F81.zero, s - s)
Ejemplo n.º 5
0
    def testIsomorphism(self):
        """
	test for fqiso
	"""
        g = FinitePrimeFieldPolynomial(enumerate([1, 1, 0, 0, 1, 1, 1]),
                                       self.F2)
        F64b = FiniteExtendedField(2, g)
        f64iso = fqiso(self.F64, F64b)
        self.assertEqual(F64b.zero, f64iso(self.F64.zero))
        self.assertEqual(F64b.one, f64iso(self.F64.one))
        x = F64b.createElement(2)
        self.assertEqual(F64b.order(x), self.F64.order(f64iso(x)))
        g = FinitePrimeFieldPolynomial(enumerate([2, 0, 0, 1, 1]), self.F3)
        F81b = FiniteExtendedField(3, g)
        f81iso = fqiso(self.F81, F81b)
        self.assertEqual(F81b.zero, f81iso(self.F81.zero))
        self.assertEqual(F81b.one, f81iso(self.F81.one))
Ejemplo n.º 6
0
 def testCreateElement(self):
     F125 = FiniteExtendedField(5, 3)
     self.assertEqual(
         F125.createElement(6),
         F125.createElement(
             FinitePrimeFieldPolynomial(enumerate([1, 1]),
                                        FinitePrimeField.getInstance(5))))
     self.assertEqual(F125.createElement(6), F125.createElement([1, 1]))
Ejemplo n.º 7
0
 def testInit(self):
     self.assertEqual(8, card(FiniteExtendedField(2, 3)))
     f = FinitePrimeFieldPolynomial(enumerate([1, 1, 0, 1]),
                                    FinitePrimeField.getInstance(2))
     self.assertEqual(8, card(FiniteExtendedField(2, f)))
     for i in range(10):  # 10 might be enough to check random moduli
         F8 = FiniteExtendedField(2, 3)
         defining_polynomial = F8.modulus
         self.assert_(defining_polynomial.degree() == 3)
         self.assert_(defining_polynomial.isirreducible())
Ejemplo n.º 8
0
 def testRepr(self):
     f = FinitePrimeFieldPolynomial(
         [(0, 2), (8, 1)], coeffring=FinitePrimeField.getInstance(311))
     self.assertEqual(0, repr(f).index("Finite"))