Ask Your Question
0

calculating the modulo of a "number" in a binary finite field

asked 2017-09-04 08:02:35 +0100

neubert gravatar image

Polynomial equations in binary finite fields are often represented as numbers. eg. $x^2 + 1$ is basically the same thing as $1x^2 + 0x^1 + 1x^0$ and thus would be represented as $101_2$ or $5_{10}$.

In that spirit I'm trying to use a hexadecimal number to represent a polynomial equation. The polynomial equation is larger than the modulo I'm using ($x^{113} + x^9 + 1$) so I'm trying to get the result of the modulo operation.

Here's what I've tried:

BF.<a> = FiniteField(2^113);

X = Integer(0x61661990d3b1f7a608ad095a01d727380850d2592f5b9f88f66a20e8);
X_bf = BF._cache.fetch_int(X);

X_bf.mod(x^113 + x^9 + 1)

Unfortunately, this doesn't seem to work and instead gets me the following error messages:

TypeError                                 Traceback (most recent call last)
<ipython-input-4-dba4addbde0d> in <module>()
      2 
      3 X = Integer(Integer(0x61661990d3b1f7a608ad095a01d727380850d2592f5b9f88f66a20e8));
----> 4 X_bf = BF._cache.fetch_int(X);
      5 
      6 X_bf.mod(x**Integer(113) + x**Integer(9) + Integer(1))

/home/sage/sage-8.0/src/sage/rings/finite_rings/element_ntl_gf2e.pyx in sage.rings.finite_rings.element_ntl_gf2e.Cache_ntl_gf2e.fetch_int (/home/sage/sage/src/build/cythonized/sage/rings/finite_rings/element_ntl_gf2e.cpp:7596)()
    400         raise ValueError("Cannot coerce element %s to this field." % e)
    401 
--> 402     cpdef FiniteField_ntl_gf2eElement fetch_int(self, number):
    403         """
    404         Given an integer less than `p^n` with base `2`

/home/sage/sage-8.0/src/sage/rings/finite_rings/element_ntl_gf2e.pyx in sage.rings.finite_rings.element_ntl_gf2e.Cache_ntl_gf2e.fetch_int (/home/sage/sage/src/build/cythonized/sage/rings/finite_rings/element_ntl_gf2e.cpp:7212)()
    431 
    432         if number < 0 or number >= self.order():
--> 433             raise TypeError("n must be between 0 and self.order()")
    434 
    435         if isinstance(number, int) or isinstance(number, long):

TypeError: n must be between 0 and self.order()

I realize that what I'm doing isn't technically a finite field but idk how else I might get a "number" turned into a polynomial equation.

Any ideas?

edit retag flag offensive close merge delete

Comments

What you could do is the following:

sage: F.<x> = GF(2)[]
sage: p = F(X.bits())
sage: BF(p)
a^110 + a^106 + a^105 + a^103 + a^101 + a^100 + a^99 + a^98 + a^97 + a^95 + a^94 + a^91 + a^87 + a^86 + a^85 + a^84 + a^82 + a^81 + a^80 + a^78 + a^77 + a^75 + a^72 + a^69 + a^68 + a^67 + a^65 + a^63 + a^60 + a^59 + a^58 + a^57 + a^56 + a^53 + a^52 + a^51 + a^50 + a^45 + a^41 + a^39 + a^38 + a^37 + a^31 + a^30 + a^28 + a^23 + a^21 + a^20 + a^19 + a^17 + a^16 + a^13 + a^12 + a^11 + a^8 + a^7 + a^6 + a^5

As a side comment, note that if you simply define BF as GF(2 ...(more)

B r u n o gravatar imageB r u n o ( 2017-09-04 14:53:22 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-09-04 21:09:43 +0100

nbruin gravatar image

Why are you messing with _cache? It seems the following just works:

sage: k.<a>=GF(2^113)
sage: z=a^113+a^9+1
sage: z.integer_representation()
556
sage: k.fetch_int(556)
a^9 + a^5 + a^3 + a^2
sage: k.fetch_int(556) == z
True
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-09-04 08:02:35 +0100

Seen: 1,056 times

Last updated: Sep 04 '17