In cryptography a lot of security definitions (IND-CPA, IND-CCA etc.) are represented as games between an adversary and a challenger. Is there an existing package or a simple way to achieve this effect?
-
A couple of references that you might find useful: Drawing network protocols and Replicate this chart using LaTeX.– Claudio FiandrinoMay 21, 2013 at 13:01
-
I found this very helpful, particularly Chapter 4 and 5: ftp.dante.de/tex-archive/macros/latex/contrib/cryptocode/…– Sune JakobsenJan 13, 2016 at 3:39
1 Answer
This should get you most of the way there. It's quite a motley assembly of things. Please feel free to inquire further for elaboration. (Note: I left my original definitions of \lextlinearrow
and \rextlinearrow
in place but redefined them. The original definitions do the overtext in \tiny
rather than normal fontsize.)
\documentclass{article}
\parskip 1ex
\usepackage{amssymb}
\usepackage{verbatimbox}
\usepackage{multirow}
\usepackage{scalerel}
\newcommand{\extline}{$\scriptsize$-$\normalsize$\!}
\newcommand{\lextlineend}{$\scriptsize$\lhd\!$\normalsize$}
\newcommand{\rextlineend}{$\scriptsize\rule{.1ex}{0ex}$\rhd$\normalsize$}
\newcounter{index}
\newcommand\extlines[1]{%
\setcounter{index}{0}%
\whiledo {\value{index}< #1}
{\addtocounter{index}{1}\extline}
}
\newcommand\rextlinearrow[2]{$
\setbox0\hbox{$\extlines{#2}\rextlineend$}%
\tiny$%
\!\!\!\!\begin{array}{c}%
\mathrm{#1}\\%
\usebox0%
\end{array}%
$\normalsize$\!\!%
}
\newcommand\lextlinearrow[2]{$
\setbox0\hbox{$\lextlineend\extlines{#2}$}%
\tiny%
$%
\!\!\!\!\begin{array}{c}%
\mathrm{#1}\\%
\usebox0%
\end{array}%
$\normalsize$\!\!%
}
\renewcommand\lextlinearrow[2]{%
\setbox0\hbox{$\lextlineend\extlines{#2}$}%
\shortstack{$\mathrm{#1}$\\\addvbuffer[-.7ex -.3ex]{\usebox0}}%
}
\renewcommand\rextlinearrow[2]{%
\setbox0\hbox{$\extlines{#2}\rextlineend$}%
\shortstack{$\mathrm{#1}$\\\addvbuffer[-.7ex -.3ex]{\usebox0}}%
}
\begin{document}
\noindent
\begin{tabular}{clc}
{\large Challenger} & & {\large Adversary}\\
picks random k and &&\\
picks random b$\in$\{0,1\}&&\\
\multirow{2}{*}{\addvbuffer[1.1ex]{Repeat n times}\scaleto{\{}{7ex}}&
\lextlinearrow{P_i}{26} &\\
& \rextlinearrow{\mathbf{E}_k[P_i]}{26} &\\
& \lextlinearrow{M_0, M_1}{26} & picks M$_0$, M$_1$ of equal length \\
& \rextlinearrow{C = \mathbf{E}_k[M_b]}{26} &\\
& \lextlinearrow{b' \in \{0,1\}}{26} &\\
& Attacker wins game if b = b'&
\end{tabular}
\end{document}
See No \xrightrightarrow[a]{b}? and How do I put text over a squiggly arrow? for discussion of where I came up with the text over extensible symbol idea. However, I actually like my current approach of using \shortstack
better, even though it builds up from the baseline, rather than vertically centering the result.
-
thank you, but for some reason \addvbuffer[-.7ex -.3ex]{\usebox0} appears as as -7.ex -.3ex (text) for me May 21, 2013 at 14:46
-
@Uku Loskit Make sure you have version 3.0 or later of verbatimbox (ctan.org/pkg/verbatimbox) May 21, 2013 at 14:57
-