6

An example of a cryptographic game

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?

lockstep
  • 250,273

1 Answers1

3

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}

enter image description here

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.

David Carlisle
  • 757,742