答案1
也许你想考虑tikzpeople
绘制此类方案的包
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\usepackage{tikzpeople}
\begin{document}
\begin{tikzpicture}[mylabel/.style={text width=8 mm, align=center}]
\node[bob, minimum width=1.5cm,
label={[mylabel, anchor=west]north east:{Public\\ n, e}},
label={[mylabel, anchor=east]north west:{Private\\ d}}] (bob) {Bob};
\node[alice, minimum width=1.5cm, right=5cm of bob, mirrored,
label={[mylabel, anchor=east]north west:{Public}},
label={[mylabel, anchor=west]north east:{Private\\ M}}] (alice) {Alice};
\draw[->, thick, blue] ([yshift=2mm]bob.east) coordinate(aux-a)-- coordinate[near start] (aux) node[above, text width=1.5cm, align=center]{Alice reads e and n} (aux-a-|alice.west);
\draw[<-, thick, blue] ([yshift=-2mm]bob.east) coordinate(aux-b)-- node[below, text width=1.5cm, align=center]{Alice sends M'} coordinate[near end] (auxtwo) (aux-b-|alice.west);
\node[devil, minimum width=1.5cm, below right=5mm and 2cm of bob] (eve) {Eve};
\draw[->,red, ultra thick] (eve-|aux)--(aux);
\draw[->,red, ultra thick] (eve-|auxtwo)--(auxtwo);
\end{tikzpicture}
\end{document}
答案2
你可以从这个开始:
\documentclass{article}
\usepackage{tikz}
\usepackage{mathtools}
\usepackage{minibox}
\begin{document}
\begin{tikzpicture}
\def\rectanglepath{-- ++(5cm,0cm) -- ++(0cm,5cm) -- ++(-5cm,0cm) -- cycle}
\draw (0,0) \rectanglepath;
\node at (2.5,4) {Bob};
\node at (1.5,3) {private};
\node at (3.5,3) {public};
\node at (1.5,2.5) {d};
\node at (3.5,2.5) {n,e};
\node at (5.9,3) {$\xrightarrow{\makebox[1.6cm]{\minibox{Alice reads\\ e and n}}}$};
\draw (7,0) \rectanglepath;
\node at (9.5,4) {Alice};
\node at (8.5,3) {private};
\node at (10.5,3) {public};
\node at (10.5,2.5) {M};
\node at (6.2,1.5) {$\xleftarrow{\makebox[1.5cm]{\minibox{Alice\\ sends\\ M}}}$};
\draw (2.4,3.5) .. controls (3,2) and (3,2) .. (2.2,0.3);
\draw (9.6,3.5) .. controls (9.5,2) and (9.2,2) .. (10.2,0.3);
\draw[red] (5.2,2.6) -- (5.2,-1); %red lines
\draw[red] (6.2,0.9) -- (6.2,-1); %red lines
\def\rectanglepath{-- ++(2cm,0cm) -- ++(0cm,2cm) -- ++(-2cm,0cm) -- cycle}
\draw (4.6,-3) \rectanglepath;
\node at (5.6,-2) {Eve};
\end{tikzpicture}
.
\end{document}
控件的作用是:
点 1 和 2 是直线 [红色] 和曲线的端点。C1 和 C2 是曲线的控制点。它们像磁铁一样将直线吸引到它们的方向。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%line
\draw[red](0,0) -- (4,4);
%curve
\draw (0,0) .. controls (0,4) and (4,0) .. (4,4);
\draw [black, fill=white] (0,0) circle (3pt) node[right] {1};%1st endpoint
\draw [black, fill=white] (4,4) circle (3pt) node[right] {2};%2st endpoint
\draw [black, fill=white] (0,4) circle (3pt) node[right] {C1};%controlpoint 1
\draw [black, fill=white] (4,0) circle (3pt) node[right] {C2};%controlpoint 2
\draw[->, thick] (0.8,2) -- (0,3.9);
\draw[->, thick] (3.4,2) -- (4,0.2);
\end{tikzpicture}
\end{document}
答案3
使用@Roland 答案作为起点(作为 OP MWE)并采用图像元素的相对定位:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
calc,
fit,
positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 1mm,
B/.style = {align=center},
E/.style = {B, draw, inner xsep=3mm},
FIT/.style = {draw, fit=#1},
N/.style = {B, font=\large\bfseries},
every edge quotes/.style = {auto, font=\small, align=center},
every edge/.style = {draw=gray, very thick, -{Straight Barb[scale=0.5]},
shorten >=2mm},
]
\node[N] (bob) {Bob};
%
\node[B,below left=of bob] (b1) {private\\ d};
\node[B,below right=of bob] (b2) {public\\ n, e};
\coordinate[below=of b1.south -| bob] (bob');
\draw (bob) to [bend left] (bob');
\node[FIT=(bob) (b1) (b2) (bob')] (fitL) {};
%%%%
\node[N,
right=44mm of bob -| fitL.east] (alice) {Alice};
%
\node[B,below left=of alice] (a1) {private\\ d};
\node[B,below right=of alice] (a2) {public\\ n, e};
\coordinate[below=of a1.south -| alice] (alice');
\draw (alice) to [bend right] (alice');
\node[FIT=(alice) (a1) (a2) (alice')] (fitR) {};
% messages
\draw ([yshift= 5mm] fitL.east) coordinate (fL)
edge ["Alice reads\\ e and n"] (fL -| fitR.west)
([yshift=-5mm] fitR.west) coordinate (fR)
edge ["Alice sends\\ M'" '] (fR -| fitL.east);
% eve
\node[E, below=of $(fitL.south east)!0.5!(fitR.south west)$] (eye) {Eve};
% looks
\draw[red, semithick, dashed]
([xshift=-2mm] eye.north) -- ([xshift= 3mm] fL)
([xshift= 2mm] eye.north) -- ([xshift=-3mm] fR);
\end{tikzpicture}
\end{document}