我尝试将此算法写入我的 latex 文件中。但是它出现编译错误:
! 缺少插入 \endcsname。
我已经确定问题出在 for 循环中,删除 for 循环以外的所有内容后也出现相同错误。请指出我做错的地方。
\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
\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}