## RCM3720 Cryptography, Network and Computer Security

### Laboratory Class 11: Finite Fields

- Enter the following definition of the finite field

                 3
         Z [x]/(x +x+1)
          2

  - F:=FFP(PF 2,x^3+x+1)
- To perform field operations, we need to create a generator of the field: a symbol which can be used to generate all elements as polynomials:
  - x:=generator()$F
    Now field arithmetic is easy:
  - (x^2+1)(x+1) in the field:
    - (x^2+1)*(x+1)
  - 1/(x^2+x):
    - 1/(x^2+x)
      Note that Axiom returns its answer in terms of a dummy variable.
  - We can also list tables of powers:
    - for i in 0..7 repeat output (i::String, x^i)
- Before we enter a new field, we need to clear `x` and its properties:
  - )cl pr x
  Now for a slightly bigger field:

                 4  3
         Z [x]/(x +x +1)
          2

  - F2:=FFP(PF 2,x^4+x^3+1)
  - Create a list of powers of `x`.
  - Evaluate (x^3+x+1)/(x^3+x^2) in this field.
- Enter the Rijndael field,

               8  4  3
       Z [x]/(x +x +x +x+1)
        2

  and call it `GR`.
- Determine whether `x` is a primitive element in this field:
  - x:=generator()$GR
  - primitive?(x)
- Is `x+1` a primitive element?
- Investigate the workings of MixColumn. First create the matrix:
  - M:Matrix GR:=matrix([[x,x+1,1,1],[1,x,x+1,1],[1,1,x,x+1],[x+1,1,1,x]])
- Instead of multiplying a matrix `C` by `M`, we shall just look at a single column, created randomly:
  - C:Matrix GR:=matrix([[random()$FR] for j in 1..4])
These can be multiplied directly in Axiom:

- D:=M*C

- Remarkably enough, Axiom can operate on matrices over a finite field as easily as it can operate on numerical matrices. For example, given that

         D=MC

- it follows that

            -1
         C=M  D

- or that

          -1
         M  D-C=0

- To test this, first create the matrix inverse:
  - MI:=inverse(M)
- Now multiply by `D` and subtract `C`. What does the result tell you about the truth of the final equation?
- To explore MixColumn a bit more, we shall look at the inverse of `M`. First, here's a small function which converts from a polynomial to an integer (treating the coefficients of the polynomial as digits of a binary number):
  - poly2int(p)==(tmp:=reverse(coordinates(p)),return integer wholeRadix(tmp::LIST INT)$RadixExpansion(2))
- First check the matrix `M`:
  - map((x +-> poly2int(x)::INT), M)
- Is this what you should have?
- Now apply the same command but to `MI` instead of to `M`. What is the result?