Exemplo n.º 1
0
 def createElement(self, seed):
     """
     Create an element of the field.
     """
     if isinstance(seed, int):
         expansion = arith1.expand(seed, card(self.basefield))
         return ExtendedFieldElement(
             uniutil.FiniteFieldPolynomial(enumerate(expansion),
                                           self.basefield), self)
     elif seed in self.basefield:
         return ExtendedFieldElement(
             uniutil.FiniteFieldPolynomial([(0, seed)], self.basefield),
             self)
     elif seed in self:
         # seed is in self, return only embedding
         return self.zero + seed
     elif (isinstance(seed, uniutil.FiniteFieldPolynomial)
           and seed.getCoefficientRing() is self.basefield):
         return ExtendedFieldElement(seed, self)
     else:
         try:
             # lastly check sequence
             return ExtendedFieldElement(
                 uniutil.FiniteFieldPolynomial(enumerate(seed),
                                               self.basefield), self)
         except TypeError:
             raise TypeError("seed %s is not an appropriate object." %
                             str(seed))
Exemplo n.º 2
0
 def _random_irriducible(char, degree):
     """
     Return randomly chosen irreducible polynomial of self.degree.
     """
     cardinality = char**degree
     basefield = FinitePrimeField.getInstance(char)
     seed = bigrandom.randrange(1, char) + cardinality
     cand = uniutil.FiniteFieldPolynomial(enumerate(
         arith1.expand(seed, cardinality)),
                                          coeffring=basefield)
     while cand.degree() < degree or not cand.isirreducible():
         seed = bigrandom.randrange(1, cardinality) + cardinality
         cand = uniutil.FiniteFieldPolynomial(enumerate(
             arith1.expand(seed, cardinality)),
                                              coeffring=basefield)
     _log.debug(cand.order.format(cand))
     return cand
Exemplo n.º 3
0
 def _getZero(self):
     "getter for zero"
     if self._zero is None:
         self._zero = ExtendedFieldElement(
             uniutil.FiniteFieldPolynomial([], self.basefield), self)
     return self._zero
Exemplo n.º 4
0
 def _getOne(self):
     "getter for one"
     if self._one is None:
         self._one = ExtendedFieldElement(
             uniutil.FiniteFieldPolynomial([(0, 1)], self.basefield), self)
     return self._one