9

I want to produce network protocols, a very simplified example of which is depicted below:

A simple protocol

The protocol has two parties, each of which does some computation and then communicated with the other.

I can use a 3-column table, but I want to know if there is any better solution. Especially, whether there is any particular package for this, or any simple way to do it in TikZ.

egreg
  • 1,121,712
Sadeq Dousti
  • 4,380
  • 1
    Don't you think the image is a little too sparse? Visually it doesn't convey the message that the time is going downwards. I think the arrows need to have a target and a source. Of course I have no idea what are the specific practices of your field but still it can be a little intuitive. – percusse May 01 '12 at 21:02

2 Answers2

8

Here is my simple solution using the method shown here:

\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains, calc}
\begin{document}

\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, nodes={draw=none, anchor=center,text depth=0pt} ]{
Prover & & Verifier\\[-4mm]
Choose a random number & & \\[-7mm]
$r \in \{0,1\}^{*}.$ & & \\
 & Send $r$ & \\
& & Choose a random number  \\[-7mm]
& &$s \in \{0,1\}^{*}.$\\
 & Send $s$ & \\
};

\draw[shorten <=-1.5cm,shorten >=-1.5cm] (m-1-1.south east)--(m-1-1.south west);
\draw[shorten <=-1.5cm,shorten >=-1.5cm] (m-1-3.south east)--(m-1-3.south west);
\draw[shorten <=-1cm,shorten >=-1cm,-latex] (m-4-2.south west)--(m-4-2.south east);
\draw[shorten <=-1cm,shorten >=-1cm,-latex] (m-7-2.south east)--(m-7-2.south west);
\end{tikzpicture}
\end{document}

EDIT The graphical result is:

enter image description here

David Carlisle
  • 757,742
  • 4
    It's always nice to have an image of the result. The standalone class or pdfcrop can help here. It is recommended to convert it to a PNG yourself before uploading. You can use \documentclass[png]{standalone} and then compile with pdflatex -shell-escape (needs Image Magic to be installed). – Martin Scharrer May 01 '12 at 20:35
8

Did you look at MSC (Message Sequence Charts) package in CTAN? I've never used but some of our students did it.

EDIT Your example could be done with some code like this

\documentclass[border=2mm]{standalone}
\usepackage{msc}
\begin{document}
\begin{msc}{Example}
\declinst{prover}{}{Prover}
\declinst{verifier}{}{Verifier}
\action*{%
\begin{minipage}{3cm}\centering 
Choose a random number\\
$r\in\{0,1\}^*$
\end{minipage}%
}{prover}
\nextlevel[4]
\mess{Send $r$}{prover}{verifier}
\nextlevel
\action*{%
\begin{minipage}{3cm}\centering
Choose a random number\\
$r\in\{0,1\}^*$
\end{minipage}}{verifier}
\nextlevel[4]
\mess{Send $s$}{verifier}{prover}
\end{msc}
\end{document}

and the result (with xelatex because msc uses pstricks) is

enter image description here

The apperance is not so flexible because msc diagrams are normalized by ITU (International Telecomunication Union) and the package respects the format.

David Carlisle
  • 757,742
Ignasi
  • 136,588
  • When I try to run your example I run into an undefined control sequence: \c@lor@to@ps ->\PSTricks _Not_Configured_For_This_Format. – lucidbrot Nov 29 '20 at 17:58
  • 1
    @lucidbrot I've tested again and it works without problems. Did you use xelatex to compile it? Do you use an updated TeX system? – Ignasi Nov 29 '20 at 18:44
  • Thanks for testing! I've tried on two systems - one with texLive and one with MikTex. At least the latter one I completely reinstalled. But no, I did not run it with xelatex but with pdflatex. I have now tried again using xelatex and it failed again. But running it a second time with xelatex without any changes made it work. So... I guess I'll have to read up what the difference between pdflatex and xelatex is. – lucidbrot Nov 29 '20 at 19:43