[Tex/LaTex] Error in algorithm: Missing \endcsname inserted

algorithmspdftex

I am trying to write this algorithm in my latex file. However it comes with a compilation error:

! Missing \endcsname inserted.

I have pin pointed the problem to be in the for loop and after removing everything except the for loop also has the same error. Please suggest where I am doing wrong.

\documentclass[12pt]{article}
\usepackage[ruled,lined]{algorithm2e}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}
\caption{Key Expansion of AES-128}
        \SetKwInOut{Input}{input}
        \SetKwInOut{Output}{output}
        \Input{128 bit secret key}
        \Output{11 round keys each of 4 words as $w[0], \dots, w[43]$}
    \SetKwBlock{Beginn}{beginn}{ende}
    \Begin{
            \State $Rcon[1] \leftarrow 01000000$\;
            \State $Rcon[2] \leftarrow 02000000$\;
            \State $Rcon[3] \leftarrow 04000000$\;
            \State $Rcon[4] \leftarrow 08000000$\;
            \State $Rcon[5] \leftarrow 10000000$\;
            \State $Rcon[6] \leftarrow 20000000$\;
            \State $Rcon[7] \leftarrow 40000000$\;
            \State $Rcon[8] \leftarrow 80000000$\;
            \State $Rcon[9] \leftarrow 1B000000$\;
            \State $Rcon[10] \leftarrow 36000000$\;
        \For{$i \leq 0$ to $3$}{
                $w[i] \leftarrow (k[4i], k[4i+1], k[4i+2], k[4i+3])$
        }\EndFor
        \For{$i \leq 4$ to $43$}{
                \State $temp \leftarrow w[i-1]$\;
                \If{$i \equiv 0(mod4)$} {
                        \State $temp = SUBWORD(ROTWORD(temp))\oplus RCon[i/4]$\;
                }\EndIf
                $w[i] \leftarrow w[i-4] \oplus temp$\;
        }\EndFor
        \Return $(w[0], \dots, w[43])$
    }
\end{algorithm}

\end{document}

Best Answer

\documentclass[12pt]{article}
\usepackage[ruled,lined]{algorithm2e}
%\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}
\caption{Key Expansion of AES-128}
         \SetKwInOut{Input}{input}
        \SetKwInOut{Output}{output}
        \Input{128 bit secret key}
        \Output{11 round keys each of 4 words as $w[0], \dots, w[43]$}
    \SetKwBlock{Beginn}{beginn}{ende}
    \Begin{
            %\State 
            $Rcon[1] \leftarrow 01000000$\;
        %     \State 
        $Rcon[2] \leftarrow 02000000$\;
        %     \State 
        $Rcon[3] \leftarrow 04000000$\;
        %     \State 
        $Rcon[4] \leftarrow 08000000$\;
        %     \State 
        $Rcon[5] \leftarrow 10000000$\;
        %     \State 
        $Rcon[6] \leftarrow 20000000$\;
        %     \State 
        $Rcon[7] \leftarrow 40000000$\;
        %     \State 
        $Rcon[8] \leftarrow 80000000$\;
        %     \State 
        $Rcon[9] \leftarrow 1B000000$\;
        %     \State 
        $Rcon[10] \leftarrow 36000000$\;
        \For{$i \leq 0$ to $3$}{
                $w[i] \leftarrow (k[4i], k[4i+1], k[4i+2], k[4i+3])$
        }%\EndFor
        \For{$i \leq 4$ to $43$}{
                %\State 
                $temp \leftarrow w[i-1]$\;
                \If{$i \equiv 0(mod4)$} {
                        %\State
                        $temp = SUBWORD(ROTWORD(temp))\oplus RCon[i/4]$\;
                }%\EndIf
                $w[i] \leftarrow w[i-4] \oplus temp$\;
        }%\EndFor
        \Return $(w[0], \dots, w[43])$
    }
\end{algorithm}

\end{document}

enter image description here