AES ShiftRow Confusion I'm implementing AES and I'm getting confused in the ShiftRows step. So far, my key expansion and SubBytes works and I get the same output as specified by the NIST publication. 

For the ShiftRows Steps, if we refer to the test vector below from NIST, the output is incorrect according to this:



Round 1, from NIST page 35:

--------------------------------------------------------------
state:      63cab7040953d051cd60e0e7ba70e18c &lt;-- SubBytes() 
state:      6353e08c0960e104cd70b751bacad0e7 &lt;-- ShiftRows()
--------------------------------------------------------------


If we consider the matrix below:

$$\begin{pmatrix}
S_{00} &amp; S_{01} &amp; S_{02} &amp; S_{03} \\  
S_{10} &amp; S_{11} &amp; S_{12} &amp; S_{13} \\  
S_{20} &amp; S_{21} &amp; S_{22} &amp; S_{23} \\  
S_{30} &amp; S_{31} &amp; S_{32} &amp; S_{33} \\ 
\end{pmatrix}$$

$$\begin{pmatrix}
\texttt{63} &amp; \texttt{ca} &amp; \texttt{b7} &amp; \texttt{04} \\  
\texttt{09} &amp; \texttt{53} &amp; \texttt{d0} &amp; \texttt{51} \\
\texttt{cd} &amp; \texttt{60} &amp; \texttt{e0} &amp; \texttt{e7} \\
\texttt{ba} &amp; \texttt{70} &amp; \texttt{e1} &amp;  \texttt{8c} \\
\end{pmatrix}$$

Then the output is clearly different.

$$\begin{pmatrix}
\texttt{63} &amp; \texttt{ca} &amp; \texttt{b7} &amp; \texttt{04} \\  
\texttt{53} &amp; \texttt{d0} &amp; \texttt{51} &amp; \texttt{09} \\
\texttt{e0} &amp; \texttt{e7} &amp; \texttt{cd} &amp; \texttt{60} \\
\texttt{8c} &amp; \texttt{ba} &amp; \texttt{70} &amp; \texttt{e1} \\
\end{pmatrix}$$
The state must be written/read along the columns:

63cab7040953d051cd60e0e7ba70e18c $\mapsto$ $
\begin{bmatrix}
63 &amp; 09 &amp; cd &amp; ba \\
ca &amp; 53 &amp; 60 &amp; 70 \\
b7 &amp; d0 &amp; e0 &amp; e1 \\
04 &amp; 51 &amp; e7 &amp; 8c
\end{bmatrix}
$

shift rows $\mapsto$ $
\begin{bmatrix}
63 &amp; 09 &amp; cd &amp; ba \\
53 &amp; 60 &amp; 70 &amp; ca \\
e0 &amp; e1 &amp; b7 &amp; d0 \\
8c &amp; 04 &amp; 51 &amp; e7 
\end{bmatrix}
$ $\mapsto$ 6353e08c0960e104cd70b751bacad0e7

See Figure 3 in FIPS SP 197, 3.4 (http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf).