# AES S-box calculation

I am trying to design the s-box for AES. Quoting from Wikipedia, the algorithm for applying affine transformation in AES s-box calculation is

Let s (an 8-bit unsigned variable) be the input number.
Let result be 0.
For 5 times:
XOR result with s.
Rotate s one bit to the left.


My question is why the multiplication is done this way? Why only 5 steps?

• look at the affine matrix, each column and row only has 5 bits set – Richie Frame Mar 14 '18 at 21:04