%
% schieberegister.tex -- template for standalon tikz images
%
% (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
%
\documentclass[tikz]{standalone}
\usepackage{amsmath}
\usepackage{times}
\usepackage{txfonts}
\usepackage{pgfplots}
\usepackage{csvsimple}
\usetikzlibrary{arrows,intersections,math}
\begin{document}
\def\skala{1}
\begin{tikzpicture}[>=latex,thick,scale=\skala]

\definecolor{darkgreen}{rgb}{0,0.6,0}

\def\s{0.8}

\def\punkt#1#2{({#1*\s},{#2*\s})}

\fill[color=blue!20] \punkt{0}{0} rectangle \punkt{8}{1};

\node at \punkt{0.5}{1} [above] {$X^7\mathstrut$};
\node at \punkt{3}{1}   [above] {$+\mathstrut$};
\node at \punkt{3.5}{1} [above] {$X^4\mathstrut$};
\node at \punkt{5}{1}   [above] {$+\mathstrut$};
\node at \punkt{5.5}{1} [above] {$X^2\mathstrut$};
\node at \punkt{7}{1}   [above] {$+\mathstrut$};
\node at \punkt{7.5}{1} [above] {$1\mathstrut$};

\node at \punkt{0}{1} [above left] {\llap{$p(X)=\mathstrut$}};

\node at \punkt{0.5}{0.5} {\texttt{1}};
\node at \punkt{1.5}{0.5} {\texttt{0}};
\node at \punkt{2.5}{0.5} {\texttt{0}};
\node at \punkt{3.5}{0.5} {\texttt{1}};
\node at \punkt{4.5}{0.5} {\texttt{0}};
\node at \punkt{5.5}{0.5} {\texttt{1}};
\node at \punkt{6.5}{0.5} {\texttt{0}};
\node at \punkt{7.5}{0.5} {\texttt{1}};

\draw \punkt{0}{0} rectangle \punkt{8}{1};
\foreach \x in {1,...,7}{
	\draw \punkt{\x}{0} -- \punkt{\x}{1};
}

\fill[color=blue!20] \punkt{-1}{-3} rectangle \punkt{7}{-2};
\fill[color=darkgreen!20] \punkt{0}{-4} rectangle \punkt{8}{-3};

\node[color=darkgreen] at \punkt{-1}{-1.5} [left] 
	{$m(X) = X^8+X^4+X^3+X+1$};

\node[color=darkgreen] at \punkt{-1}{-2.7} [left]
	{$\underbrace{X^4+X^3+X+1}_{}= X^8=\mathstrut$};

\coordinate (A) at ({-4.15*\s},{-3*\s});
\coordinate (B) at ({0*\s},{-3.5*\s});

\draw[->,color=red,shorten >= 0.1cm] (A) to[out=-90,in=180] (B);
\node[color=red] at \punkt{-3.1}{-3.8} [below] {Feedback};

\node at \punkt{-0.5}{-2.5} {\texttt{1}};
\node at \punkt{0.5}{-2.5} {\texttt{0}};
\node at \punkt{1.5}{-2.5} {\texttt{0}};
\node at \punkt{2.5}{-2.5} {\texttt{1}};
\node at \punkt{3.5}{-2.5} {\texttt{0}};
\node at \punkt{4.5}{-2.5} {\texttt{1}};
\node at \punkt{5.5}{-2.5} {\texttt{0}};
\node at \punkt{6.5}{-2.5} {\texttt{1}};
\node at \punkt{7.5}{-2.5} {\texttt{0}};

\node[color=darkgreen] at \punkt{0.5}{-3.5} {\texttt{0}};
\node[color=darkgreen] at \punkt{1.5}{-3.5} {\texttt{0}};
\node[color=darkgreen] at \punkt{2.5}{-3.5} {\texttt{0}};
\node[color=darkgreen] at \punkt{3.5}{-3.5} {\texttt{1}};
\node[color=darkgreen] at \punkt{4.5}{-3.5} {\texttt{1}};
\node[color=darkgreen] at \punkt{5.5}{-3.5} {\texttt{0}};
\node[color=darkgreen] at \punkt{6.5}{-3.5} {\texttt{1}};
\node[color=darkgreen] at \punkt{7.5}{-3.5} {\texttt{1}};

\draw \punkt{0}{-4} rectangle \punkt{8}{-2};
\draw \punkt{0}{-3} -- \punkt{8}{-3};
\foreach \x in {1,...,7}{
	\draw \punkt{\x}{-4} -- \punkt{\x}{-2};
}

\foreach \x in {0.5,1.5,...,7.5}{
	\draw[->,color=blue] \punkt{\x}{-0.1} -- \punkt{(\x-1)}{-1.9};
}

\draw \punkt{0}{-6} rectangle \punkt{8}{-5};
\foreach \x in {1,...,7}{
	\draw \punkt{\x}{-6} -- \punkt{\x}{-5};
}

\node at \punkt{0.5}{-5.5} {\texttt{0}};
\node at \punkt{1.5}{-5.5} {\texttt{0}};
\node at \punkt{2.5}{-5.5} {\texttt{1}};
\node at \punkt{3.5}{-5.5} {\texttt{1}};
\node at \punkt{4.5}{-5.5} {\texttt{0}};
\node at \punkt{5.5}{-5.5} {\texttt{0}};
\node at \punkt{6.5}{-5.5} {\texttt{0}};
\node at \punkt{7.5}{-5.5} {\texttt{1}};

\node at \punkt{4}{-4.5} {$\|$};

\node at \punkt{10.3}{-3} [left]
	{$\left.\begin{matrix}\\ \\ \\ \end{matrix}\right\} + = \text{XOR}$};

\draw[<-,shorten >= 0.1cm, shorten <= 0.1cm]
	\punkt{8.0}{-2.0} arc (-30:30:{2.0*\s});
\node at \punkt{8.3}{-1} [right] {$\mathstrut \cdot X$};

\node at \punkt{8.1}{-5.5} [right] {$=X\cdot p(X)\mathstrut$};

\end{tikzpicture}
\end{document}

