6. SubBytes

Let's finally take a look at what a round looks like!

round

That's right. Here's are all the operations that are computed on the state, in order:

  1. SubBytes
  2. ShiftRows
  3. MixColumns
  4. AddRoundKey

And that's all there is to a round. AES-128, the variant of AES that takes a 128-bit key, has 10 rounds in total. Each round takes as input a different round key and the previous round's output. Note that the last round is a bit different from the other rounds, the last round skips the MixColumns transformation. With that in mind we will start by implementing SubBytes, the first transformation in an AES round.

Create a subBytes() function that takes a state, and returns or modify the new state after the SubBytes transformation.

What is the SubBytes transformation? It is an S-box: it takes a byte and returns a corresponding byte according to a look-up table. We've already covered that in the SubWord function, and good news, this one uses the same S-box.

If you want to test your function, you can use the values of this page's diagram.

Once you're done, go on to the next step!

Next