
250 Cryptography with Open-Source Software
sage: b1 = 1/b; b1
x^6 + x^5 + x^4 + x^2 + 1
Now for the affine transformation:
sage: R.<y> = PolynomialRing(GF(2))
sage: a = y^4+y^3+y^2+y+1
sage: c = y^6+y^5+y+1
sage: q = (a*b1.polynomial().subs(x=y)+c).mod(y^8+1); q
y^7 + y^6 + y^4 + y^2 + 1
This last polynomial corresponds to the byte 11010101 as above.
The S-box transformation can be equivalently described using matrices.
Suppo se b
′
is defined a s above, a nd so
b
′
= b
7
b
6
b
5
b
4
b
3
b
2
b
1
b
0
.
Then the S-box output is the byte z = z
7
z
6
z
5
z
4
z
3
z
2
z
1
z
0
for which
1 0 0 0 1 1 1 1
1 1 0 0 0 1 1 1
1 1 1 0 0 0 1 1
1 1 1 1 0 0 0 1
1 1 1 1 1 0 0 0
0 1 1 1 1 1 0 0
0 0 1 1 1 1