[Tex/LaTex] Colored horizontal lines in algorithm2e

algorithm2ecolorrules

I'm trying to colorize the 3 horizontal lines appearing at the top and bottom of the algorithm below. I haven't been able to find similar issues in the internet. Could you please advise?

\documentclass[11pt,a4paper]{article}
\usepackage[no-math]{fontspec}
\usepackage[dvipsnames,svgnames,table,fixpdftex]{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[ruled,linesnumbered]{algorithm2e}


\begin{document}        

\begin{algorithm}
\SetArgSty{textnormal}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\DontPrintSemicolon
\Input{A point $P$, an $n$-bit integer $k=\displaystyle\sum_{i=0}^{n-1} k_{(i)}2^i$}
\Output{$Q=[k]P$}
\Begin{
 $Q \longleftarrow \mathcal{O}$\;
 \For{$i=n-1$ to $0$}
 {
    $Q \longleftarrow [2]Q$\;
    \If{$k_{(i)}=1$}{
        $Q \longleftarrow Q+P$
    }
 }
 \Return{$Q$}
}

\caption{Binary method for EC point multiplication} \label{alg1}
\end{algorithm}

\end{document}

Result is shown below.
The lines with the arrows need to get some color

Best Answer

The following setup allows you to adjust these colours to suit your needs via the provided macros:

\setalgotoprulecolor{<colour>}
\setalgomidrulecolor{<colour>}
\setalgobotrulecolor{<colour>}

enter image description here

\documentclass{article}

\usepackage[dvipsnames,svgnames,table]{xcolor}
\usepackage{amsmath,amssymb}
\usepackage[ruled,linesnumbered]{algorithm2e}

% algorithm2e settings
\SetArgSty{textnormal}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\DontPrintSemicolon
\newcommand{\assign}{\longleftarrow}

\makeatletter
\newcommand{\setalgotoprulecolor}[1]{\colorlet{toprulecolor}{#1}}
\let\old@algocf@pre@ruled\@algocf@pre@ruled % Adjust top rule colour
\renewcommand{\@algocf@pre@ruled}{\textcolor{toprulecolor}{\old@algocf@pre@ruled}}

\newcommand{\setalgobotrulecolor}[1]{\colorlet{bottomrulecolor}{#1}}
\let\old@algocf@post@ruled\@algocf@post@ruled % Adjust middle rule colour
\renewcommand{\@algocf@post@ruled}{\textcolor{bottomrulecolor}{\old@algocf@post@ruled}}

\newcommand{\setalgomidrulecolor}[1]{\colorlet{midrulecolor}{#1}}
\renewcommand{\algocf@caption@ruled}{%
  \box\algocf@capbox{\color{midrulecolor}\kern\interspacetitleruled\hrule
    width\algocf@ruledwidth height\algotitleheightrule depth0pt\kern\interspacealgoruled}}
\makeatother

\setalgotoprulecolor{blue!30}% Default
\setalgobotrulecolor{red!30}% Default
\setalgomidrulecolor{green!30}% Default

\begin{document}        

\begin{algorithm}
  \Input{A point $P$, an $n$-bit integer $k = \sum_{i=0}^{n-1} k_{(i)}2^i$}
  \Output{$Q = [k]P$}
  \Begin{
   $Q \assign \mathcal{O}$\;
   \For{$i = n-1$ to $0$}
   {
      $Q \assign [2]Q$\;
      \If{$k_{(i)} = 1$}{
          $Q \assign Q + P$
      }
   }
   \Return{$Q$}
  }
  \caption{Binary method for EC point multiplication}
\end{algorithm}

\end{document}

The above code is specific to the ruled style of algorithm2e.