绘制按位运算的包-建议?

绘制按位运算的包-建议?

是否有任何软件包可以绘制图表,以说明通过逐位操作(在字节级别)处理几个 32/64 位变量,类似于下面的图表?如果没有,也许有什么建议可以实现这种类型的图表?提前谢谢!

在此处输入图片描述

答案1

TikZ拖延一些时间可以对你有帮助。

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning, arrows.meta, matrix, backgrounds, shapes.misc}

\begin{document}
\begin{tikzpicture}[
    >=Latex,
    font=\sffamily,
    word/.style={matrix of nodes,
        inner sep=0pt,
        nodes={draw, minimum height=6mm, minimum width=3mm},
        column sep=-\pgflinewidth, nodes in empty cells}
]

\matrix[word] (opool1)
{&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\};
\draw[thick] (opool1.north west) rectangle (opool1.south east);  
\draw[ultra thick] (opool1.north) -- (opool1.south); 

\node[rounded rectangle, below=1cm of opool1, draw] (sha1) {Sha 1};

\matrix[word, below =5mm of sha1] (hash1) {&&&&\\};
\draw[thick] (hash1.north west) rectangle (hash1.south east); 

\node[rounded rectangle, below=5mm of hash1, draw] (mix) {mixing};

\matrix[word, below=5mm of mix] (opool2)
{&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\};
\draw[thick] (opool2.north west) rectangle (opool2.south east); 
\begin{scope}[on background layer]
\fill[blue!50] (opool2-1-1.north west) rectangle (opool2-1-13.south east);
\fill[blue!50] (opool2-1-26.north west) rectangle (opool2-1-32.south east);
\end{scope}

\matrix[word, below=5mm of opool2] (opool3)
{&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\};
\draw[thick] (opool3.north west) rectangle (opool3.south east); 
\begin{scope}[on background layer]
\fill[violet!50] (opool3-1-11.north west) rectangle (opool3-1-26.south east);
\end{scope}

\node[rounded rectangle, below=8mm of opool3, draw] (sha2) {Sha 1};

\matrix[word, below =5mm of sha2] (hash2) {&&&&\\};
\draw[thick] (hash2.north west) rectangle (hash2.south east); 
\draw[ultra thick] (hash2.north) -- (hash2.south); 

\node[rounded rectangle, below=5mm of hash2, draw, minimum width=15mm] (fold) {fold};

\node[draw, thick, minimum width=7mm, minimum height=6mm, below=5mm of fold] (end) {};

%arrows
\draw[<-](sha1.north)--++(90:4mm)--(opool1.south west); 
\draw[<-](sha1.north)--++(90:4mm)--(opool1.south east); 
\draw[->](sha1)--(hash1);
\draw[->](hash1)--(mix);
\draw[->]([yshift=-2mm]sha1.south)-|([xshift=-2mm]opool2.west)|-(sha2);
\draw[->](mix.south)--++(-90:1mm)-|(opool2-1-13.north);
\draw[->](opool2)--(opool3);
\draw[->](opool3-1-18.south east)--++(-90:4mm)-| coordinate[pos=.25] (aux) (sha2);
\draw (aux)--+(135:2mm)--+(-45:2mm);
\draw[->](sha2)--(hash2);
\draw[->](hash2-1-2.south)--(hash2-1-2.south|-fold.north);
\draw[->](hash2-1-4.south)--(hash2-1-4.south|-fold.north);
\draw[->](fold)--(end);
\draw[->]([yshift=1mm]opool2-1-13.north west)--([yshift=1mm]opool2.north west);
\draw[->]([yshift=1mm]opool2.north east)--([yshift=1mm]opool2-1-27.north west);

%labels
\node[above=1mm of opool1-1-8.north east] {16 32-bit words};
\node[above=1mm of opool1-1-24.north east] {16 32-bit words};
\node[left=4mm of opool1] (lo1) {output pool};
\node[left=0mm of lo1.east|-hash1] {5-word hash};
\node[right=2mm of mix.east] {5 words = 20 bytes};
\node[left=0mm of lo1.east|-opool2] {output pool};
\node[left=0mm of lo1.east|-opool3] {output pool};
\node[right=5mm of aux] {16 words};
\node[left=0mm of lo1.east|-hash2] {5-word hash};
\node[left=0mm of lo1.east|-end] {10-byte output};

%side labels
\draw ([shift={(1mm,1mm)}]opool1.north east)--++(0:3mm)|-([shift={(1mm,-1mm)}]opool2.south east) node[pos=.25, rotate=270, right=1mm, anchor=south]{feedback phase}; 
\coordinate (aux3) at ([yshift=-1mm]end.south);
\draw ([shift={(1mm,1mm)}]opool3.north east)--++(0:3mm) coordinate(aux2)--(aux2|-aux3) node[midway, rotate=270, right=1mm, anchor=south]{extraction phase}--++(180:3mm); 

%red marks
\begin{scope}[>={Turned Square[length=2mm]}, thick, red]
\draw[<-] (opool1-1-13.north)--++(90:3mm);
\draw[<-] (opool2-1-14.north)--++(90:3mm);
\draw[<-] (opool2-1-26.north)--++(90:3mm);
\draw[<-] (opool3-1-26.north)--++(90:3mm);
\draw[<-] ([shift={(15mm,5mm)}]end.east)--++(90:3mm) coordinate (aux4);
\node[black, right=2mm of aux4, align=left] (aux5) {position of last\\ added byte};
\draw[black] (aux5.north east) rectangle ([xshift=-5mm]aux5.south west);
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容