\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}

\newcommand\Algphase[1]{%
\vspace*{-.7\baselineskip}\Statex\hspace*{\dimexpr-\algorithmicindent-2pt\relax}\rule{\textwidth}{0.4pt}%
\Statex\hspace*{-\algorithmicindent}\textbf{#1}%
\vspace*{-.7\baselineskip}\Statex\hspace*{\dimexpr-\algorithmicindent-2pt\relax}\rule{\textwidth}{0.4pt}%
}
\begin{document}
\addcontentsline{toc}{chapter}{پیوست‌ها}

\appendix
\chapter{‌پیوست‌ها}\label{chp:peyvast}

\renewcommand{\algorithmiccomment}[1]{$\triangleright$ #1}
\begin{algorithm}
 \caption{ایجاد سهم برای سهام‌داران در طرح
 $ (2 , 2 ) -OVCS $
 و
 $(2 , 2 ) -XVCS $}
 \label{alg2}
 \begin{latin}   
 \begin{algorithmic}[1]
 
 \REQUIRE image ,$ MatrixS^{0} , MatrixS^{1}$
 \ENSURE shareFile
\vskip.5\baselineskip\hrule height 0.4pt\vskip.5\baselineskip


 \STATE  \COMMENT{  PaternList $MatrixS^{0} = Column\,  permutation\, MatrixS^{0}$}
 \STATE  \COMMENT{PaternList $MatrixS^{1} =  Column\, permutation\, MatrixS^{1}$}
  \STATE  \COMMENT{ Consider a list of images called sharefile  in memory }
     
         \FOR{ each members}\\ 
     \COMMENT{Add a picture the size of Secret * sqrt (Column $MatrixS^{0}$) to shareFile} 
       \ENDFOR        
   \FOR{ each pixel in Image}  
       
             \IF{pixel color is white}\\
 \COMMENT{  Patern <- select Random of PaternList $MatrixS^{0}$}
   \ENDIF
        \IF{pixel color is black}\\
\COMMENT{Patern <- select Random of PaternList $MatrixS^{1}$}
  \ENDIF
  
 \ENDFOR
\FOR{ each share in shareFile}\\
        $    k = sqrt(Column MatrixS^{0}) * pixel.x ;$ \qquad 
        
          $  l = sqrt(Column MatrixS^{0}) * pixel.y ; $
          \ENDFOR
 \FOR{ $ i \, \, to  \, \, sqrt(Column MatrixS^{0})$}\\
 \FOR{$ j \, \,  to \, \,  sqrt(Column MatrixS^{0})$ }\\
 
            \IF {row[m],Column[n] in Patern is zero}\\
             \COMMENT{  set pixel[k + i, l + j] of share[m] to white }
          \ENDIF      
          \IF { row[m],Column[n] in Patern is one}\\
      \COMMENT{  set pixel[k + i, l + j] of share[m] to black}
 \ENDIF
 \ENDFOR
  \ENDFOR
 \STATE  \textbf{Return} shareFile

 \end{algorithmic}
 \end{latin}
 \end{algorithm}



\begin{algorithm}
 \caption{ایجاد سهم برای سهام‌داران در طرح
ناحیه به ناحیه}
 \label{alg3}
 \begin{latin}   
 \begin{algorithmic}[1]
 
 \REQUIRE image , $Matrix S_{1}^{0} , Matrix S_{1}^{1} , Matrix S_{2}^{0} , Matrix S_{2}^{1}$
 \ENSURE shareFile
\vskip.5\baselineskip\hrule height 0.4pt\vskip.5\baselineskip


 \STATE  \COMMENT{  Nahiyeh1=coding(image,$Matrix S_{1}^{0} , Matrix S_{1}^{1}$)  by  \ref{alg2}}
 \STATE  \COMMENT{Nahiyeh2=coding(image,$Matrix S_{2}^{0} , Matrix S_{2}^{1}$)  by  \ref{alg2}}
 
     
         \FOR{ each Nahiyeh1,Nahiyeh2} 
     \COMMENT{shareFile[m]=Attach Nahiyeh1[m] to Nahiyeh2[m]} 
       \ENDFOR   
            
   
 \STATE  \textbf{Return} shareFile

 \end{algorithmic}
 \end{latin}
 \end{algorithm}

 
 \begin{algorithm}
 \caption{بازسازی تصویر راز با عملگر 
 $ XOR$}
 \label{alg4}
 \begin{latin}   
 \begin{algorithmic}[1]
 
 \REQUIRE Sharefile
 \ENSURE Secret
\vskip.5\baselineskip\hrule height 0.4pt\vskip.5\baselineskip


 \STATE  \COMMENT{  picture secret the size of listshare[0]}
      
         \FOR{pixel in secret} 
            
             \IF{listshare[0](pixel.x,pixel.y) is white}
 \COMMENT{   flag = 0}
   \ENDIF
        \IF{listshare[0](pixel.x,pixel.y) is black}
\COMMENT{flag = 1}
  \ENDIF
  
 \ENDFOR
 
\FOR{ share in listshare }
\COMMENT{ except listshare[0]}
     \IF{listshare[0](pixel.x,pixel.y) is white}
 \COMMENT{  flag2 = 0}
   \ENDIF
        \IF{listshare[0](pixel.x,pixel.y) is black}
\COMMENT{ flag2 = 1}
  \ENDIF    
          \ENDFOR
          
       \COMMENT{flag=XOR(flag,flag2)}  
        
             \IF {flag is 1}
             \COMMENT{  set pixel of secret to black }
          \ENDIF      
          \IF { flag is 0}
      \COMMENT{  set pixel of secret to white}
 \ENDIF
  \STATE  \textbf{Return} secret

 \end{algorithmic}
 \end{latin}
 \end{algorithm}
 
 \begin{algorithm}
 \caption{بازسازی تصویر راز با عملگر 
 $ OR$}
 \label{alg5}
 \begin{latin}   
 \begin{algorithmic}[1]
 
 \REQUIRE Sharefile
 \ENSURE Secret
\vskip.5\baselineskip\hrule height 0.4pt\vskip.5\baselineskip


 \STATE  \COMMENT{  picture secret the size of listshare[0]}
      
         \FOR{pixel in secret} 
            
             \IF{listshare[0](pixel.x,pixel.y) is white}
 \COMMENT{   flag = 0}
   \ENDIF
        \IF{listshare[0](pixel.x,pixel.y) is black}
\COMMENT{flag = 1}
  \ENDIF
  
 \ENDFOR
 
\FOR{ share in listshare }
\COMMENT{ except listshare[0]}
     \IF{listshare[0](pixel.x,pixel.y) is white}
 \COMMENT{  flag2 = 0}
   \ENDIF
        \IF{listshare[0](pixel.x,pixel.y) is black}
\COMMENT{ flag2 = 1}
  \ENDIF    
          \ENDFOR
          
       \COMMENT{flag=OR(flag,flag2)}  
        
             \IF {flag is 1}
             \COMMENT{  set pixel of secret to black }
          \ENDIF      
          \IF { flag is 0}
      \COMMENT{  set pixel of secret to white}
 \ENDIF
  \STATE  \textbf{Return} secret

 \end{algorithmic}
 \end{latin}
 \end{algorithm}
 \end{document}