# Understanding Cryptography by Christof Paar and Jan Pelzl - Chapter 4 Solutions - Ex4.14

- 4 mins- Return to index
- Exercise 4.1
- Exercise 4.2
- Exercise 4.3
- Exercise 4.4
- Exercise 4.5
- Exercise 4.6
- Exercise 4.7
- Exercise 4.8
- Exercise 4.9
- Exercise 4.10
- Exercise 4.11
- Exercise 4.12
- Exercise 4.13
- Exercise 4.14
- Exercise 4.15
- Exercise 4.16

## Exercise 4.14

Your task is to compute the S-Box, i.e., the ByteSub, values for the input bytes 29, F3 and 01, where each byte is given in hexadecimal notation.

- First, look up the inverses using Table 4.2 to obtain values . Now, perform the affine mapping by computing the matrix–vector multiplication and addition.
- Verify your result using the S-Box Table 4.3.
- What is the value of ?

### Solution

*This solution is verified as correct by the fact that it produces sensible output which can be checked against Table 4.3.*

1. We can reuse the inverses we looked up in Ex4.13:

The next step is to perform the affine mapping (which destroys the mathematical relationship inherent to the Galois Field aspect of S-box and makes it thoroughly non-linear). This involves a bitwise matrix multiplication (AND) and a bitwise XOR which is defined as follows:

It should be noted here that is the least significant (rightmost) bit which may be the reverse of your intuition.

To start with , we already know the values for because of the lookup we did (and verified) in the previous exercise. Its inverse is .

Applying the matrix multiplication and the XOR, you get the following:

Next, we calculate the inverse of :

Applying the matrix multiplication and the XOR, you get the following:

Finally, we calculate the inverse of :

Applying the matrix multiplication and the XOR, you get the following:

2. Checking these results in Table 4.3 confirms them as correct.

3. 0 technically has no inverse (there is no value which produces 1 when multiplied with 0), but 0 is treated as its own inverse. This means that the affine mapping will take the value of the final XOR ()

These results can also be checked using the following python script which can perform the Affine Mapping: