1

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}
1
  • Is the use of both packages algpseudocode and algorithm2e absolutely required??? Commented Jul 25, 2019 at 9:21

1 Answer 1

3
\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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.