5. Understanding the State of AES

aes internal state

The plaintext fed to AES, and that is then manipulated until it becomes the ciphertext, is internaly represented as a square of 4 rows and 4 columns. This AES internal square representation is called a "state", and the different transformations applied to it through-out the encryption (or decryption) are regrouped in rounds each involving a different round key. The round keys are derived from the main key. (This should sound familiar by now.)

Your first task will be to implement the internal state representation of AES. It is visually represented as a 4x4 square where each box is a byte. But this is only a visual representation. In code you can implement that as you wish: you could create an internal structure containing 4 arrays of 4 bytes (that would hold the columns of the square), or use an array of 16 bytes... whatever you think is best.

Don't worry too much about this: the important piece here is to represent the bytes correctly. This is because we will operate on these bytes later on. And this step will make more sense as we continue to implement AES. You can always come back here later and re-implement the internal representation of a state.

Once you are done, declare this plaintext in code: this is one text and transform it into an AES state. Then implement a function printState() that will print a state as a 4x4 square on the screen. Be careful, the input is represented in columns and not in rows! (See the first diagram appearing in this page.) If everything worked correctly, here is what you should see displayed:

74 20 6f 74
68 69 6e 65
69 73 65 78
73 20 20 74

If you're set, go to the next step!

Next