%\iffalse %<*package> \NeedsTeXFormat{LaTeX2e} \DeclareRelease{v0.30}{2018-11-11}{cryptocode-2018-11-11.sty} \DeclareRelease{v0.32}{2020-04-24}{cryptocode-2020-04-24.sty} \DeclareCurrentRelease{v0.40}{2020-07-10} \ProvidesPackage{cryptocode} [2020/07/10 v0.40 Cryptocode LaTeX package for typesetting pseudocode, algorithms and protocols as well as cryptographic proofs.] % %\fi % \iffalse % Doc-Source file to use with LaTeX2e % Copyright (C) 2020 Arno Mittelbach, all rights reserved. % \fi % \iffalse %<*driver> \documentclass{ltxdoc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[usenames]{xcolor} \usepackage{hypdoc} \usepackage[ n, operators, advantage, sets, adversary, landau, probability, notions, logic, ff, mm, primitives, events, complexity, oracles, asymptotics, keys]{cryptocode} \createpseudocodeblock{pcb}{center,boxed}{}{}{} \createprocedureblock{procb}{center,boxed}{}{}{} \usepackage{csquotes} \usepackage{fullpage} \usepackage{dashbox} \usepackage{textcomp} \usepackage{url} \usepackage{xspace} \usetikzlibrary{shapes.callouts} \usepackage{listings} \usepackage{trace} \usepackage{makeidx} \usepackage{mdframed} \definecolor{mygreen}{rgb}{0,0.6,0} \definecolor{mygray}{rgb}{0.1,0.1,0.1} \definecolor{verylightgray}{rgb}{0.9,0.9,0.9} \definecolor{mymauve}{rgb}{0.58,0,0.82} \let\amipagebreak\pagebreak \setlength{\textwidth}{386pt} \addtolength\marginparwidth{50pt} \addtolength\oddsidemargin{40pt} \addtolength\evensidemargin{40pt} \lstset{language=[LaTeX]TeX, backgroundcolor=\color{verylightgray}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor} rulecolor=\color{lightgray}, basicstyle=\scriptsize, % the size of the fonts that are used for the code breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace breaklines=true, % sets automatic line breaking captionpos=b, % sets the caption-position to bottom commentstyle=\color{mygreen}, % comment style escapeinside={\%*}{*)}, % if you want to add LaTeX within your code extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8 frame=single, % adds a frame around the code keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible) keywordstyle=\color{blue}, % keyword style numbers=left, % where to put the line-numbers; possible values are (none, left, right) numbersep=5pt, % how far the line-numbers are from the code numberstyle=\scriptsize\color{mygray}, % the style that is used for the line-numbers rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here)) showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces' showstringspaces=false, % underline spaces within strings only showtabs=false, % show tabs within strings adding particular underscores stepnumber=1, % the step between two line-numbers. If it's 1, each line will be numbered stringstyle=\color{mymauve}, % string literal style frameround=ftff, belowskip=-0.8 \baselineskip, aboveskip=1em, tabsize=2, % sets default tabsize to 2 spaces title=\lstname } \CodelineIndex \CodelineIndex \RecordChanges \begin{document} \DocInput{cryptocode.dtx} \end{document} % %\fi % % \changes{v0.10}{2015/03/30}{Initial version} % \changes{v0.11}{2016/11/30}{changed command pckeystyle to ensure that subscripts on $\sk$ and $\pk$ are aligned the same % before, $(\sk_R, \pk_R)$ had slightly misaligned subscripts due to Tex treating % subscripts on composite objects with descenders differently than without.} % ^^A see \url{https://groups.google.com/forum/#!msg/comp.text.tex/IaXu_xBG06Q/CibRPH5GCAAJ} % % \changes{v0.11}{2016/11/30}{Added \textbackslash{}NAND command.} % \changes{v0.11}{2016/11/30}{Added \emph{pcmbox} environment for matrices in pseudocode.} % % \changes{v0.20}{2016/12/02}{Changed \emph{minheight} for bbrbox environment to actually reflect a minimum height in tikz. % The old minheight which added space at the bottom was preserved as \emph{addheight}.} % \changes{v0.20}{2016/12/02}{Added namepos middle for bbrbox.} % \changes{v0.20}{2016/12/02}{Added \textbackslash{}pcfail.} % \changes{v0.20}{2016/12/02}{Added valign to pseudocode to allow minipage vertical alignment.} % \changes{v0.20}{2016/12/02}{Ensure line numbers are right aligned to allow for two digit linenumbers having the same width.} % % \changes{v0.04}{2017/08/26}{added \textbackslash{}pcabort.} % \changes{v0.04}{2017/08/26}{better control whitespace for \textbackslash{}pcif, \textbackslash{}pcelse, \textbackslash{}pcelseif.} % % \changes{v0.05}{2017/10/02}{side and oside support to \textbackslash{}bbroracleqryto and \textbackslash{}bbroracleqryfrom} % \changes{v0.05}{2017/10/02}{add bottom to namepos in bbrbox} % \changes{v0.05}{2017/10/02}{names for brrinput and bbroutput} % \changes{v0.05}{2017/10/02}{angle for bbrloop} % \changes{v0.05}{2017/10/02}{fix length for bbrinput} % \changes{v0.05}{2017/10/02}{introduce hoffset for bbrinput} % % \changes{v0.06}{2017/12/21}{added \textbackslash{}pcunless} % % \changes{v0.30}{2018/11/11}{replace obsolete l3regex} % % \changes{v0.31}{2018/11/26}{added \textbackslash{}tprob (variants for prob and co for in-text)} % \changes{v0.31}{2018/11/26}{added \textbackslash{}prp} % % \changes{v0.32}{2020/01/11}{allow to control spacing with \textbackslash{}pcfor} % \changes{v0.32}{2020/01/11}{allow overwriting rule command in pseudocode via headlinecmd (defaults to \textbackslash{}hrule)} % % \changes{v0.40}{2020/06/20}{Bigger refactoring. Not completely backwards compatible. In particular, optimized spacing of pseudocode blocks and black box reductions.} % \changes{v0.40}{2020/06/20}{Switched to mathtools \emph{DeclarePairedDelimiter} for paired operators. % Each paired operator comes in two forms, e.g, \emph{abs} and \emph{tabs} the latter to be used in flowtext % which does not scale the outer delimiters.} % \changes{v0.40}{2020/06/20}{Adjusted spacing via \textbackslash{}pcaboveskip and \textbackslash{}pcbelowskip which are % added to \textbackslash{}pseudocode blocks and \emph{pchstack} environments} % \changes{v0.40}{2020/06/20}{Added block forms for pseudocode and procedure commands (\textbackslash{}pseudocodeblock and \textbackslash{}procedureblock).} % \changes{v0.40}{2020/06/20}{Added minlineheight option to \textbackslash{}pseudocode.} % \changes{v0.40}{2020/06/20}{Added headheight option to \textbackslash{}pseudocode.} % \changes{v0.40}{2020/06/20}{Added \textbackslash{}argmax and \textbackslash{}argmin to operators.} % \changes{v0.40}{2020/06/20}{Added \textbackslash{}pindist, \textbackslash{}sindist, and \textbackslash{}cindist to operators.} % \changes{v0.40}{2020/06/20}{Added aboveskip and belowskip option to \textbackslash{}pchstack and \textbackslash{}pcvstack.} % \changes{v0.40}{2020/06/20}{Added boxed, inline, noindent options to \textbackslash{}pchstack and \textbackslash{}pcvstack.} % \changes{v0.40}{2020/06/20}{Added space option to \textbackslash{}pchstack and \textbackslash{}pcvstack.} % \changes{v0.40}{2020/06/20}{Renamed horizontal spacing commands \textbackslash{}beforepcskip and \textbackslash{}afterpcskip to \textbackslash{}pcbeforeskip and \textbackslash{}pcafterskip.} % \changes{v0.40}{2020/06/20}{Added command \textbackslash{}pcsetargs to define default arguments for pseudocode blocks.} % \changes{v0.40}{2020/06/20}{Added command \textbackslash{}pcsethstackargs and \textbackslash{}pcsetvstackargs to define default arguments for hstack and vstack environments.} % \changes{v0.40}{2020/06/20}{Adapted bbrenv environment to take key value option list. Old format is still supported but deprecated.} % \changes{v0.40}{2020/06/20}{Added additional polynomials.} % \changes{v0.40}{2020/06/20}{Added additional adversaries.} % \changes{v0.40}{2020/06/20}{Added additional complexity classes.} % \changes{v0.40}{2020/06/20}{Added oracles package option.} % \changes{v0.40}{2020/06/20}{Fixed spacing issues with black box reduction messages.} % \changes{v0.40}{2017/10/02}{Added clockwise, leftstyle, centerstyle, rightstyle for bbrloop. Adjusted placing of center.} % \changes{v0.40}{2017/10/02}{Added fixedoffset, fixedboffset, islast for reduction messages.} % % % % % % \author{Arno Mittelbach\\ % \texttt{mail@arno-mittelbach.de}\\ % \url{https://github.com/arnomi/cryptocode}\thanks{If you use cryptocode in your work, consider starring the repository on GitHub and/or rating it on CTAN.}} % \title{\Huge Cryptocode \\ \large\textsc{Typesetting Cryptography}} % % % \maketitle % % % % % \begin{abstract} % \thispagestyle{empty} % The cryptocode package provides a set of macros to ease the typesetting of % pseudocode, algorithms and protocols (such as the one below). In addition it comes with a wide range of tools to typeset cryptographic papers (hence the name). % This includes simple predefined commands for typesetting probabilities and \enquote{commonly encountered math} % as well as for concepts such as % a security parameter $\secparam$ or advantage terms $\advantage{prf}{\adv,\prf} = \negl$. Furthermore, it includes % environments to layout game-based proofs or black-box reductions. % % \vspace{2em} % \begin{center} % \fbox{ % \pseudocode{% % \textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline] % \<\< \\[-0.5\baselineskip] % x \sample \ZZ_q \< \< \\ % X \gets g^x \<\< \\[-4ex] % \< \sendmessageright*{\GG,q,g,X} \< \\[-2ex] % \<\< y \sample \ZZ_q \\ % \<\< Y \gets g^y \\[-4ex] % \< \sendmessageleft*{Y} \< \\ % \key_A \gets Y^x \<\< \key_B \gets X^y } % } % \end{center} % % % \end{abstract} % \newpage % % \pagenumbering{roman} % % \tableofcontents % \thispagestyle{empty} % \newpage % % \pagenumbering{arabic} % % % \section{Cryptocode by Example} % % The cryptocode package provides a set of commands to ease the typesetting of % pseudocode, protocols, game-based proofs and black-box reductions. In addition it comes % with a large number of predefined commands. In this section we present the various features of % cryptocode by giving small examples. But first, let's load the package % % \iffalse %<*example> % \fi \begin{lstlisting} \usepackage[ n, % or lambda advantage, operators, sets, adversary, landau, probability, notions, logic, ff, mm, primitives, events, complexity, oracles, asymptotics, keys ]{cryptocode}\end{lstlisting} % \iffalse % % \fi % % Note that all the options refer to a set of commands. That is, without any options cryptocode will provide the mechanisms % for writing pseudocode, protocols, game-based proofs and black-box reductions but not define additional commands, % such as |\pk| or |\sk| (for typesetting public and private/secret keys) which are part of the keys option. % We discuss the various options and associated commands in Section~\ref{chap:commands}. % % % \subsection{Pseudocode} % The cryptocode package tries to make writing pseudocode easy and enjoyable. The % |\pseudocode| command takes a single parameter where you can start writing % code in mathmode using \lstinline{\\} as line breaks. Following is an $\indcpa$ game % definition using various commands from cryptocode to ease writing keys (\lstinline{\pk,\sk}), % sampling (\lstinline{\sample}), and more: % % \medskip % \pseudocode[linenumbering]{ % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam) \\ % (\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c, \state) \\ % \pcreturn b = b' } % % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocode[linenumbering]{ b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c, \state) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % \amipagebreak % % In many cases, we want to set pseudocode blocks in-between paragraphs with spacing % similar to how we would offset equations. For this, and for laying out multiple code % blocks, cryptocode offers \enquote{stacking} environments |\pchstack| and |\pcvstack|. % For typesetting a code block nicely centered and boxed % \begin{pchstack}[center,boxed] % \pseudocode[linenumbering]{ % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam) \\ % (\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c, \state) \\ % \pcreturn b = b' } % \end{pchstack} % you could thus use: % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pchstack}[center,boxed] \pseudocode[linenumbering]{ b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c, \state) \\ \pcreturn b = b' } \end{pchstack}\end{lstlisting} % \iffalse % % \fi % % As this is a common task, cryptocode offers the |\pseudocodeblock| command which % is a shorthand for the above (without the frame). In case you want to provide different % options or a shorter command (say |\pcb|) you can easily define the command via % % \iffalse %<*example> % \fi \begin{lstlisting} \createpseudocodeblock{pcb}{center,boxed}{}{}{} \end{lstlisting} % \iffalse % % \fi % The above could now be written, more succinctly as % \iffalse %<*example> % \fi \begin{lstlisting} \pcb[linenumbering]{ b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c, \state) \\ \pcreturn b = b' }\end{lstlisting} % \iffalse % % \fi % % % The pseudocode command (and its block variant) takes a single mandatory argument (the code) plus an optional argument % which allows you to specify options in a key=value fashion. In the above example we used the linenumbering % option. % % \medskip % % It is easy to define a heading for your code. Either specify the header using the option \enquote{head} or use % the |\procedure| command (or its block variant |\procedureblock|) which takes an additional argument to specify the headline. % % \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secpar)$}{ % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam) \\ % (\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c, \state) \\ % \pcreturn b = b' } % % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secpar)$}{ b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c, \state) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % % Similarly to before, we can define a shorthand and boxed variant as % \iffalse %<*example> % \fi \begin{lstlisting} \createprocedureblock{procb}{center,boxed}{}{}{} \end{lstlisting} % \iffalse % % \fi % % % There is a lot more that we will discuss in detail in Section~\ref{chap:pseudocode}. Here, for example, % is the same code with an overlay explanation and a division of the pseudocode. % % \begin{pcimage} % \procb[linenumbering]{$\indcpa_\enc^\adv(\secpar)$}{ % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam)\pcnode{kgen} \pclb % \pcintertext[dotted]{Setup Completed} % (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c, \state) \\ % \pcreturn b = b' } % % \pcdraw{ % \node[rectangle callout,callout absolute pointer=(kgen),fill=orange] % at ([shift={(+3,-1)}]kgen) { % \begin{varwidth}{3cm} % $\kgen(\secparam)$ samples a public key $\pk$ and a private key $\sk$. % \end{varwidth} % }; % } % \end{pcimage} % % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pcimage} \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secpar)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam)\pcnode{kgen} \pclb \pcintertext[dotted]{Setup Completed} (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c, \state) \\ \pcreturn b = b' } \pcdraw{ \node[rectangle callout,callout absolute pointer=(kgen),fill=orange] at ([shift={(+3,-1)}]kgen) { \begin{varwidth}{3cm} $\kgen(\secparam)$ samples a public key $\pk$ and a private key $\sk$. \end{varwidth} }; } \end{pcimage} \end{lstlisting} % \iffalse % % \fi % % \subsection{Stacking} % % To arrange multiple procedures, cryptocode offers horizontal and vertical stacking % environments |\pchstack| and |\pcvstack|. In the example below we arrange four % code blocks in three columns equispaced with 1cm distance and stack two procedures % in the center column. % % \begin{pchstack}[center,space=1cm] % \procedure{A}{ % a \sample A \\ % \pcreturn a % } % % \begin{pcvstack}[boxed,space=0.5cm] % \procedure{B.1}{ % b \sample B \\ % \pcreturn b % } % \procedure{B.1}{ % b \sample B \\ % \pcreturn b % } % \end{pcvstack} % % \procedure{C}{ % c \sample C \\ % \pcreturn c % } % \end{pchstack} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pchstack}[center,space=1cm] \procedure{A}{ a \sample A \\ \pcreturn a } \begin{pcvstack}[boxed,space=0.5cm] \procedure{B.1}{ b \sample B \\ \pcreturn b } \procedure{B.1}{ b \sample B \\ \pcreturn b } \end{pcvstack} \procedure{C}{ c \sample C \\ \pcreturn c } \end{pchstack} \end{lstlisting} % \iffalse % % \fi % % \subsection{Columns} % The |\pseudocode| and |\procedure| commands allow the usage of multiple columns. % You switch to a new column by inserting a |\>|. This is similar to using an |align| % environment and placing a tabbing \& character.\footnote{In fact, the \emph{pseudocode} command % is based on amsmath's flalign environment.} % \pcb{ % \textbf{First} \> \textbf{Second} \> \textbf{Third} \> \textbf{Fourth} \\ % b \sample \bin \> b \sample \bin \> b \sample \bin \> b \sample \bin} % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{% \textbf{First} \> \textbf{Second} \> \textbf{Third} \> \textbf{Fourth} \\ b \sample \bin \> b \sample \bin \> b \sample \bin \> b \sample \bin} \end{lstlisting} % \iffalse % % \fi % As you can see the first column is left aligned the second right, the third left and so forth. % In order to get only left aligned columns you could thus always skip a column by % using |\>\>| or you can alternatively use |\<| as a shorthand for |\>\>|. % \pcb{ % \textbf{First} \< \textbf{Second} \< \textbf{Third} \< \textbf{Fourth} \\ % b \sample \bin \< b \sample \bin \< b \sample \bin \< b \sample \bin} % % \subsection{Protocols} % Using columns makes it easy to write even complex protocols. Following is a simple % three-party protocol. % \pcb{ % \textbf{Alice} \< \< \textbf{Bob} \< \< \textbf{Charlie} \\[][\hline] % \text{work} \< \< \< \< \\ % \< \sendmessageright{top=Work result,topstyle=red} \< \< \< \\ % \< \< \text{work} \< \< \\ % \< \< \< \sendmessageright{top=Work result,bottom=Bottom message} \< \\ % \< \< \< \< \text{work} \\ % \< \sendmessageleftx{8}{\text{A long message for Alice}} \< \\ % \text{finalize} \< \< \< \< } % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \textbf{Alice} \< \< \textbf{Bob} \< \< \textbf{Charlie} \\[][\hline] \text{work} \< \< \< \< \\ \< \sendmessageright{top=Work result,topstyle=red} \< \< \< \\ \< \< \text{work} \< \< \\ \< \< \< \sendmessageright{top=Work result,bottom=Bottom message} \< \\ \< \< \< \< \text{work} \\ \< \sendmessageleftx{8}{\text{A long message for Alice}} \< \\ \text{finalize} \< \< \< \< } \end{lstlisting} % \iffalse % % \fi % The commands |\sendmessageright| and |\sendmessageleft| are very flexible and % allow to style the sending of messages in various ways. Also note the |\\[][\hline]| at the end of the % first line. Here the first optional argument allows us to specify the lineheight (similarly to the behavior in an % align environment) while the second optional argument allows us to, for example, draw a horizontal line. % % \medskip % In multi-player protocols such as the one % above the commands |\sendmessagerightx| and |\sendmessageleftx| (note the x at the end) % allow to send messages over multiple columns. In the example, as we were using |\<| the % final message thus spans 8 columns. % % \medskip % For basic protocols you might also utilize the |\sendmessageright*| and |\sendmessageleft*| % commands which simply take a message which is displayed (in math mode) on top. % \pcb{ % \textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline] % \<\< \\[-0.5\baselineskip] % x \sample \ZZ_q \< \< \\ % X \gets g^x \<\< \\ % \< \sendmessageright*{\GG,q,g,X} \< \\ % \<\< y \sample \ZZ_q \\ % \<\< Y \gets g^y \\ % \< \sendmessageleft*{Y} \< \\ % \key_A \gets Y^x \<\< \key_B \gets X^y % } % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline] \<\< \\[-0.5\baselineskip] x \sample \ZZ_q \< \< \\ X \gets g^x \<\< \\ \< \sendmessageright*{\GG,q,g,X} \< \\ \<\< y \sample \ZZ_q \\ \<\< Y \gets g^y \\ \< \sendmessageleft*{Y} \< \\ \key_A \gets Y^x \<\< \key_B \gets X^y } \end{lstlisting} % \iffalse % % \fi % We will discuss protocols in greater detail in Section~\ref{chap:protocols}. % % \subsection{Game-Based Proofs} % Cryptocode supports authors in visualizing game-based proofs. It defines an environment % |gameproof| which allows to wrap a number of game procedures displaying helpful % information as to what changes from game to game and to what each step is reduced. % %\begin{gameproof} % \begin{pchstack}[center,space=1em] % \gameprocedure[linenumbering,minlineheight=1.5em]{% % \text{Step 1} \\ % \\ % \text{Step 2} % } % % \tbxgameprocedure[minlineheight=1.5em]{% % \text{Step 1} \\ % \pcbox{\text{From game 3 on}} \\ % \gamechange{\text{Step 3 is different}} % } % % \gameprocedure[minlineheight=1.5em]{% % \text{Step 1} \\ % \text{From game 3 on}\\ % \text{\gamechange{Step 3 adapted again}} % } % % \end{pchstack} %\end{gameproof} % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gameproof} \begin{pchstack}[center,space=1em] \gameprocedure[linenumbering,minlineheight=1.5em]{% \text{Step 1} \\ \\ \text{Step 3} } \tbxgameprocedure[minlineheight=1.5em]{% \text{Step 1} \\ \pcbox{\text{From game 3 on}} \\ \gamechange{\text{Step 3 is different}} } \gameprocedure[minlineheight=1.5em]{% \text{Step 1} \\ \text{From game 3 on}\\ \text{\gamechange{Step 3 adapted again}} } \end{pchstack} \end{gameproof} \end{lstlisting} % \iffalse % % \fi % Note that we made use of the option \enquote{mode=text} in the above example which tells the underlying pseudocode % command to not work in math mode but in plain text mode. We will discuss how to visualize game-based proofs in Section~\ref{chap:gbproofs}. % % \subsection{Black-Box Reductions} % Cryptocode provides a strucured syntax to visualize black-box reductions. Basically cryptocode % provides an environment to draw boxes that may have oracles and/or challengers and that can be communicated with. % Cryptocode makes heavy use of TIKZ (\url{https://www.ctan.org/pkg/pgf}) for this, which gives you % quite some control over how things should look like. Additionally, as you can specify node names % (for example the outer box in the next example is called \enquote{A}) you can easily extend the pictures % by using plain TIKZ commands. Following is an example reduction. We discuss the details in Section~\ref{chap:bbr}. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Reduction] % \pseudocode{ % \text{Do something} \\ % \text{Step 2} % } % % \begin{bbrenv}{B} % \begin{bbrbox}[name=Adversary,minheight=2.25cm] % \end{bbrbox} % % \bbrmsgto{top=$m$} % \bbrmsgfrom{top=$\sigma$} % \bbrmsgtxt{\pseudocode{% % \text{more work} % }} % \bbrmsgto{top=$m$} % \bbrmsgfrom{top=$\sigma$} % % \bbrqryto{side=$m$} % \bbrqryfrom{side=$b$} % \end{bbrenv} % % \pseudocode{ % \text{finalize} % } % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % % \begin{bbroracle}{OraA} % \begin{bbrbox}[name=Oracle 1,minheight=1cm] % \end{bbrbox} % \end{bbroracle} % \bbroracleqryto{top=$m$} % \bbroracleqryfrom{top=$b$} % % \begin{bbroracle}{OraB} % \begin{bbrbox}[name=Oracle 2,minheight=1cm] % \end{bbrbox} % \end{bbroracle} % \bbroracleqryto{top=$m$} % \bbroracleqryfrom{top=$b$} % \end{bbrenv} % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ \text{Do something} \\ \text{Step 2} } \begin{bbrenv}{B} \begin{bbrbox}[name=Adversary,minheight=2.25cm] \end{bbrbox} \bbrmsgto{top=$m$} \bbrmsgfrom{top=$\sigma$} \bbrmsgtxt{\pseudocode{% \text{more work} }} \bbrmsgto{top=$m$} \bbrmsgfrom{top=$\sigma$} \bbrqryto{side=$m$} \bbrqryfrom{side=$b$} \end{bbrenv} \pseudocode{ \text{finalize} } \end{bbrbox} \bbrinput{input} \bbroutput{output} \begin{bbroracle}{OraA} \begin{bbrbox}[name=Oracle 1,minheight=1cm] \end{bbrbox} \end{bbroracle} \bbroracleqryto{top=$m$} \bbroracleqryfrom{top=$b$} \begin{bbroracle}{OraB} \begin{bbrbox}[name=Oracle 2,minheight=1cm] \end{bbrbox} \end{bbroracle} \bbroracleqryto{top=$m$} \bbroracleqryfrom{top=$b$} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % \amipagebreak % \section{Notation Macros} % \label{chap:commands} % \index{package options} % In this section we'll discuss the various commands for notation that can be % loaded via package options. % \iffalse %<*example> % \fi \begin{lstlisting} \usepackage[ n, % or lambda advantage, operators, sets, adversary, landau, probability, notions, logic, ff, mm, primitives, events, complexity, oracles, asymptotics, keys ]{cryptocode} \end{lstlisting} % \iffalse % % \fi % % \textbf{Remark. } % Note that the available command sets are far from complete and % reflect my own work (especially once you get to cryptographic notions and primitives). % In case you feel that something should be added feel free to drop me an email, % or better yet, open an issue and pull request on github (\url{https://github.com/arnomi/cryptocode}). % % \subsection{Security Parameter} % \index{security parameter|see {package options}} % \index{package options!security parameter} % In cryptography we make use of a security parameter which is usually denoted by $1^n$ or $1^\lambda$. The cryptocode % package, when loading either option \enquote{n} or option \enquote{lambda} will define the commands % \iffalse %<*example> % \fi \begin{lstlisting} \secpar \secparam \SECPAR \end{lstlisting} % \iffalse % % \fi % The first command provides the \enquote{letter}, i.e., either $n$ or $\lambda$, whereas |\secparam| prints % |\1^\secpar| (i.e., $\secparam$ for option \enquote{n}). Finally, |\SECPAR| yields $N_0$ (resp.~$\Lambda$) % and is meant to be used in sentences such as, \enquote{there exists $\SECPAR\in\NN$ such that for all $\secpar \geq \SECPAR$, ...} % % \subsection{Advantage Terms} % Load the package option ``advantage'' in order to define the command |\advantage| used to specify advantage terms such as: % \[ % \advantage{prf}{\adv,\prf} % \] % \iffalse %<*example> % \fi \begin{lstlisting} \advantage{prf}{\adv,\prf} \end{lstlisting} % \iffalse % % \fi % Specify an optional third parameter to replace the $(\secpar)$. % \iffalse %<*example> % \fi \begin{lstlisting} \advantage{prf}{\adv,\prf}[(arg)] \end{lstlisting} % \iffalse % % \fi % In order to redefine the styles in which superscript and subscript are set, or in case % you want to replace the term $\pcadvantagename$, redefine: % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcadvantagename}{\mathsf{Adv}} \renewcommand{\pcadvantagesuperstyle}[1]{\mathrm{\MakeLowercase{#1}}} \renewcommand{\pcadvantagesubstyle}[1]{#1} \end{lstlisting} % \iffalse % % \fi % % \subsection{Math Operators} % \index{operators|see {package options}} % \index{package options!operators} % \index{math operators|see {package options}} % \index{\textbackslash{} sample} % \index{\textbackslash{} floor} % \index{\textbackslash{} tfloor} % \index{\textbackslash{} ceil} % \index{\textbackslash{} tceil} % \index{\textbackslash{} Angle} % \index{\textbackslash{} tAngle} % \index{\textbackslash{} abs} % \index{\textbackslash{} tabs} % \index{\textbackslash{} norm} % \index{\textbackslash{} tnorm} % \index{\textbackslash{} concat} % \index{\textbackslash{} emptystring} % \index{\textbackslash{} argmax} % \index{\textbackslash{} argmin} % \index{\textbackslash{} pindist} % \index{\textbackslash{} cindist} % \index{\textbackslash{} sindist} % The \enquote{operators} option provides the following list of commands: % % \begin{center} % \begin{tabular}{l p{5cm} l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} & \textbf{Example} \\\hline % |\sample| & Sampling from a distribution, or running a randomized procedure & $\sample$ & $b \sample \bin$ \\ % |\floor{42.5}| & Rounding down & $\floor{42.5}$ & \\ % |\ceil{41.5}| & Rounding up & $\ceil{41.5}$ & \\ % |\Angle{x,y}| & Vector product & $\Angle{x,y}$ & \\ % |\abs{\frac{a}{b}}| & Absolute number & $\abs{\frac{a}{b}}$ & \\ % |\norm{x}| & Norm & $\norm{x}$ & \\ % |\concat| & Verbose concatenation (I usually prefer simply \verb$\|$) & $\concat$ & $x \gets a\concat b$ \\ % |\emptystring| & The empty string & $\emptystring$ & $x \gets \emptystring$ \\ % |\argmax| & arg max & $\argmax$ & $\argmax_{x \in S} f(x)$ \\ % |\argmin| & arg min & $\argmin$ & $\argmin_{x \in S} f(x)$ \\ % |\pindist| & Perfect indistinguishability & $\pindist$ & $X \pindist Y$ \\ % |\sindist| & Statistical indistinguishability & $\sindist$ & $X \sindist Y$ \\ % |\cindist| & Computational indistinguishability & $\cindist$ & $X \cindist Y$ % \end{tabular} % \end{center} % % The paired operators |\floor|, |\ceil|, |\Angle|, |\norm|, and |\abs| also % come in a form for flow text which does not scale the outer delimter. These % are |\tfloor|, |\tceil|, |\tAngle|, |\tnorm|, and |\tabs|. % % Note that $\argmax$ and $\argmin$ in block formulas will set their subscripts as limits, i.e.,: % % \[ \argmax_{x \in S} f(x) \] % % \subsection{Adversaries} % \index{adversary|see {package options}} % \index{package options!adversary} % The \enquote{adversary} option provides the following list of commands: % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\adv| & Adversary & $\adv$ \\ % |\bdv| & Adversary & $\bdv$ \\ % |\cdv| & Adversary & $\cdv$ \\ % |\ddv| & Adversary & $\ddv$ \\ % |\edv| & Adversary & $\edv$ \\ % |\mdv| & Adversary & $\mdv$ \\ % |\pdv| & Adversary & $\pdv$ \\ % |\rdv| & Adversary & $\rdv$ \\ % |\sdv| & Adversary & $\sdv$ % \end{tabular} % \end{center} % % \noindent The style in which an adversary is rendered is controlled via % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcadvstyle}[1]{\ensuremath{\mathcal{#1}}} \end{lstlisting} % \iffalse % % \fi % % % \subsection{Landau} % \index{Landau|see {package options}} % \index{package options!Landau} % The \enquote{landau} option provides the following list of commands: % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\bigO{n^2}| & Big O(micron) notation & $\bigO{n^2}$ \\ % |\smallO{n^2}| & small o(micron) notation & $\smallO{n^2}$ \\ % |\bigOmega{n^2}| & Big Omega notation & $\bigOmega{n^2}$ \\ % |\bigTheta{n^2}| & Big Theta & $\bigTheta{n^2}$ \\ % |\orderOf| & On the order of & $f(n) \orderOf g(n)$ % \end{tabular} % \end{center} % % % \subsection{Probabilities} % \index{probability|see {package options}} % \index{package options!probabilities} % The \enquote{probability} option provides commands for writing probabilities. Use % \iffalse %<*example> % \fi \begin{lstlisting} \prob{X=x} \probsub{x\sample{\bin^n}}{x=5} \condprob{X=x}{A=b} \condprobsub{x\sample{\bin^n}}{x=5}{A=b} \end{lstlisting} % \iffalse % % \fi % to write basic probabilities, probabilities with explicit probability spaces and conditional probabilities. % \begin{align*} % & \prob{X=x} \\ % & \probsub{x\sample{\bin^n}}{X=x} \\ % & \condprob{X=x}{A=b} \\ % & \condprobsub{x\sample{\bin^n}}{x=5}{A=b} % \end{align*} % You can control the probability symbol (Pr) by redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\probname}{Pr} \end{lstlisting} % \iffalse % % \fi % The probability commands have a flowtext version |\tprob{X=X}| or |\tcondprob{X=x}{Y=y}| % which does not scale the delimiters. % In case the probability space is more complex, you can use % \iffalse %<*example> % \fi \begin{lstlisting} \probsublong{x,y\sample\set{1,2,3,4,5,6}, z = x + y}{z = 7} \end{lstlisting} % \iffalse % % \fi % which yields % \[ \probsublong{x,y\sample\set{1,2,3,4,5,6}, z = x + y}{z = 7}.\] % % % For specifying expectations the following commands are defined % \iffalse %<*example> % \fi \begin{lstlisting} \expect{X} \expsub{x,y\sample\set{1,\ldots,6}}{x+y} \condexp{X+Y}{Y>3} \condexpsub{x,y\sample\set{1,\ldots,6}}{x+y}{y>3} \end{lstlisting} % \iffalse % % \fi % yielding % \begin{align*} % & \expect{X} \\ % & \expsub{x,y\sample\set{1,\ldots,6}}{x+y} \\ % & \condexp{X+Y}{Y>3} \\ % & \condexpsub{x,y\sample\set{1,\ldots,6}}{x+y}{y>3} % \end{align*} % Again flowtext versions such as |\texpect{X}| are available. % To control the expactation symbol ($\mathbb{E}$), redefine % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\expectationname}{\ensuremath{\mathbb{E}}} \end{lstlisting} % \iffalse % % \fi % % The support $\supp{X}$ of a random variable $X$ can be written as % \iffalse %<*example> % \fi \begin{lstlisting} \supp{X} \end{lstlisting} % \iffalse % % \fi % where again the name can be controlled via % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\supportname}{Supp} \end{lstlisting} % \iffalse % % \fi % % For denoting entropy and min-entropy use % \iffalse %<*example> % \fi \begin{lstlisting} \entropy{X} \minentropy{X} \condentropy{X}{Y=5} \condminentropy{X}{Y=5} \condavgminentropy(X}{Y=5} \end{lstlisting} % \iffalse % % \fi % This yields % \begin{align*} % & \entropy{X} \\ % & \minentropy{X} \\ % & \condentropy{X}{Y=5} \\ % & \condminentropy{X}{Y=5} \\ % & \condavgminentropy{X}{Y=5} % \end{align*} % % \subsection{Sets} % \index{sets|see {package options}} % \index{package options!sets} % The \enquote{sets} option provides commands for basic mathematical sets. % You can write sets and sequences as % \iffalse %<*example> % \fi \begin{lstlisting} \set{1, \ldots, 10} \sequence{1, \ldots, 10} \end{lstlisting} % \iffalse % % \fi % which are typeset as % \begin{align*} % & \set{1, \ldots, 10} \\ % & \sequence{1, \ldots, 10} % \end{align*} % In addition, the following commands are provided % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\bin| & The set containing 0 and 1 & $\bin$ \\ % |\NN| & Natural numbers & $\NN$ \\ % |\ZZ| & Integers & $\ZZ$ \\ % |\QQ| & Rational numbers & $\QQ$ \\ % |\CC| & Complex numbers & $\CC$ \\ % |\RR| & Reals & $\RR$ \\ % |\PP| & & $\PP$ \\ % |\FF| & & $\FF$ \\ % |\GG| & & $\GG$ \\ % \end{tabular} % \end{center} % % The style in which sets are being set can be adapted by redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcsetstyle}[1]{\ensuremath{\mathbb{#1}}} \end{lstlisting} % \iffalse % % \fi % % \subsection{Cryptographic Notions} % \index{notions|see {package options}} % \index{package options!notions} % \index{Crypto notions|see {package options}} % The \enquote{notions} option defines the following list of commands: % % \begin{center} % \begin{tabular}{l p{8cm} l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\indcpa| & IND-CPA security for encryption schemes & $\indcpa$ \\ % |\indcca| & IND-CCA security for encryption schemes & $\indcca$ \\ % |\indccai| & IND-CCA1 security for encryption schemes & $\indccai$ \\ % |\indccaii| & IND-CCA2 security for encryption schemes & $\indccaii$ \\ % |\ind| & IND security & $\ind$ \\ % |\priv| & PRIV security for deterministic public-key encryption schemes & $\priv$ \\ % |\prvcda| & PRV-CDA security (for deterministic public-key encryption schemes)& $\prvcda$ \\ % |\prvrcda| & PRV\$-CDA security (for deterministic public-key encryption schemes) & $\prvrcda$ \\ % |\kiae| & Key independent authenticated encryption & $\kiae$ \\ % |\kdae| & Key dependent authenticated encryption & $\kdae$ \\ % |\mle| & Message locked encryption & $\mle$ \\ % |\uce| & Universal computational extractors & $\uce$ \\ % |\eufcma| & Existential unforgeability under chosen message attack & $\eufcma$ \\ % |\eufnacma| & Non-adaptive existential unforgeability under chosen message attack & $\eufnacma$ \\ % |\seufcma| & Strong existential unforgeability under chosen message attack & $\seufcma$ \\ % |\eufko| & Existential unforgeability under key only attack & $\eufko$ % \end{tabular} % \end{center} % % The style in which notions are displayed can be controlled via redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcnotionstyle}[1]{\ensuremath{\mathrm{#1}}} \end{lstlisting} % \iffalse % % \fi % % \subsection{Logic} % \index{logic|see {package options}} % \index{package options!logic} % The \enquote{logic} option provides the following list of commands: % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\AND| & Logical AND & $\AND$ \\ % |\NAND| & Logical NAND & $\NAND$ \\ % |\OR| & Logical OR & $\OR$ \\ % |\NOR| & Logical NOR & $\NOR$ \\ % |\XOR| & Logical XOR & $\XOR$ \\ % |\XNOR| & Logical XNOR & $\XNOR$ \\ % |\notimplies| & Negated implication & $\notimplies$ \\ % |\NOT| & not & $\NOT$ \\ % |\xor| & exclusive or & $\xor$ \\ % |\false| & false & $\false$ \\ % |\true| & true & $\true$ % \end{tabular} % \end{center} % % % \subsection{Function Families} % \index{ff|see {package options}} % \index{package options!ff} % \index{function families|see {package options}} % The \enquote{ff} option provides the following list of commands: % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\kgen| & Key generation & $\kgen$ \\ % |\pgen| & Parameter generation & $\pgen$ \\ % |\eval| & Evaluation & $\eval$ \\ % |\invert| & Inversion & $\invert$ \\ % |\il| & Input length & $\il$ \\ % |\ol| & Output length & $\ol$ \\ % |\kl| & Key length & $\kl$ \\ % |\nl| & Nonce length & $\nl$ \\ % |\rl| & Randomness length & $\rl$ % \end{tabular} % \end{center} % % The style in which these are displayed can be controlled via redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcalgostyle}[1]{\ensuremath{\mathsf{#1}}} \end{lstlisting} % \iffalse % % \fi % % % \subsection{Machine Model} % \index{machine model|see {package options}} % \index{package options!mm} % \index{mm|see {package options}} % The \enquote{mm} option provides the following list of commands: % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\CRKT| & A circuit & $\CRKT$ \\ % |\TM| & A Turing machine & $\TM$ \\ % |\PROG| & A program & $\PROG$ \\ % |\uTM| & A universal Turing machine & $\uTM$ \\ % |\uC| & A universal Circuit & $\uC$ \\ % |\uP| & A universal Program & $\uP$ \\ % |\tmtime| & Time (of a TM) & $\tmtime$ \\ % |\ppt| & Probabilistic polynomial time & $\ppt$ % \end{tabular} % \end{center} % % The style in which these are displayed can be controlled via redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcmachinemodelstyle}[1]{\ensuremath{\mathsf{#1}}} \end{lstlisting} % \iffalse % % \fi % % \amipagebreak % \subsection{Crypto Primitives} % \index{primitives|see {package options}} % \index{package options!primitives} % \index{Crypto primitives|see {package options}} % The \enquote{primitives} option provides the following list of commands: % % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\prover| & Proover & $\prover$ \\ % |\verifier| & Verifier & $\verifier$ \\ % |\nizk| & Non interactie zero knowledge & $\nizk$ \\ % |\hash| & A hash function & $\hash$ \\ % |\gash| & A hash function& $\gash$ \\ % |\fash| & A hash function & $\fash$ \\ % |\pad| & A padding function & $\pad$ \\ % |\enc| & Encryption & $\enc$ \\ % |\dec| & Decryption & $\dec$ \\ % |\sig| & Signing & $\sig$ \\ % |\sign| & Signing & $\sign$ \\ % |\verify| & Verifying & $\verify$ \\ % |\owf| & One-way function & $\owf$ \\ % |\prf| & Pseudorandom function & $\prf$ \\ % |\prp| & Pseudorandom permutation & $\prp$ \\ % |\prg| & Pseudorandom generator & $\prg$ \\ % |\obf| & Obfuscation & $\obf$ \\ % |\iO| & Indistinguishability obfuscation & $\iO$ \\ % |\diO| & Differing inputs obfuscation & $\diO$ \\ % |\mac| & Message authentication & $\mac$ \\ % |\puncture| & Puncturing & $\puncture$ \\ % |\source| & A source & $\source$ \\ % |\predictor| & A predictor & $\predictor$ \\ % |\sam| & A sampler & $\sam$ \\ % |\distinguisher| & A distinguisher & $\distinguisher$ \\ % |\dist| & A distinguisher& $\dist$ \\ % |\simulator| & A simulator & $\simulator$ \\ % |\extractor| & An extractor & $\extractor$ \\ % |\ext| & Shorthand for |\extractor| & $\ext$ % \end{tabular} % \end{center} % % The style in which these are displayed can be controlled via redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcalgostyle}[1]{\ensuremath{\mathsf{#1}}} \end{lstlisting} % \iffalse % % \fi % % \subsection{Oracles} % \index{oracles|see {package options}} % \index{package options!oracles} % The \enquote{oracles} option provides the following list of commands: % % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\oracle| & Generic oracle & $\oracle$ \\ % |\oracle[LoR]| & Custom oracle & $\oracle[LoR]$ \\ % |\ro| & Random oracle & $\ro$ \\ % |\Oracle{\sign}| & Oracle version of procedure & $\Oracle{\sign}$ % \end{tabular} % \end{center} % % The style in which these are displayed can be controlled via redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcoraclestyle}[1]{\ensuremath{\mathsf{#1}}} \end{lstlisting} % \iffalse % % \fi % % \subsection{Events} % \index{events|see {package options}} % \index{package options!events} % The \enquote{events} option provides the following list of commands. % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\event{E}| & Event \event{E} & $\event{E}$ \\ % |\nevent{E}| & Negated event \event{E} & $\nevent{E}$ \\ % |\bad| & Bad event & $\bad$ \\ % |\nbad| & Bad event & $\nbad$ % \end{tabular} % \end{center} % % \subsection{Complexity} % \index{complexity|see {package options}} % \index{package options!complexity} % The \enquote{complexity} option provides the following list of commands: % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Result} \\\hline % |\complclass{myClass}| & $\complclass{myClass}$ \\ % |\cocomplclass{myClass}| & $\cocomplclass{myClass}$ \\ % |\npol| & $\npol$ \\ % |\conpol| & $\conpol$ \\ % |\pol| & $\pol$ \\ % |\bpp| & $\bpp$ \\ % |\ppoly| & $\ppoly$ \\ % |\NC{1}| & $\NC1$ \\ % |\AC{1}| & $\AC1$ \\ % |\TC{1}| & $\TC1$ \\ % |\AM| & $\AM$ \\ % |\coAM| & $\coAM$ \\ % |\PH| & $\PH$ \\ % |\csigma{1}| & $\csigma{1}$ \\ % |\cpi{1}| & $\cpi{1}$ \\ % |\cosigma{1}| & $\cosigma{1}$ \\ % |\copi{1}| & $\copi{1}$ % \end{tabular} % \end{center} % % The style in which these are displayed can be controlled via redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pccomplexitystyle}[1]{\ensuremath{\mathsf{#1}}} \end{lstlisting} % \iffalse % % \fi % % \amipagebreak % \subsection{Asymptotics} % \index{asymptotics|see {package options}} % \index{package options!asymptotics} % The \enquote{asymptotics} option provides the following list of commands: % % \begin{center} % \begin{tabular}{l l p{7.5cm}} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |\negl| & A negligible function & $\negl$ (\secpar\ is |\secpar|) \\ % |\negl[x]| & A negligible function & $\negl[x]$ \\ % |\negl[]| & A negligible function & $\negl[]$ \\ % |\poly| & A polynomial & $\poly$ (\secpar\ is |\secpar|) \\ % |\poly[x]| & A polynomial & $\poly[x]$ \\ % |\poly[]| & A polynomial & $\poly[]$ \\ % |\pp| & some polynomial $\pp$ & $\pp$ \\ % |\pp[t]| & some custom polynomial $\pp[t]$ & $\pp[t]$ \\ % |\cc| & some polynomial $\cc$ & $\cc$ \\ % |\ee| & some polynomial $\ee$ & $\ee$ \\ % |\kk| & some polynomial $\kk$ & $\kk$ \\ % |\mm| & some polynomial $\mm$ & $\mm$ \\ % |\nn| & some polynomial $\nn$ & $\nn$ \\ % |\qq| & some polynomial $\qq$ & $\qq$ \\ % |\rr| & some polynomial $\rr$ & $\rr$ % \end{tabular} % \end{center} % % The style in which these are displayed can be controlled via redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcpolynomialstyle}[1]{\ensuremath{\mathrm{#1}}} \end{lstlisting} % \iffalse % % \fi % % \subsection{Keys} % \index{keys|see {package options}} % \index{package options!keys} % The \enquote{keys} option provides the following list of commands: % % % \begin{center} % \begin{tabular}{l l l} % \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline % |pk| &public key & $\pk$ \\ % |vk| & verification key& $\vk$ \\ % |sk| & secret key& $\sk$ \\ % |key| & a plain key& $\key$ \\ % |key[xk]| & custom key & $\key[xk]$ \\ % |hk| & hash key& $\hk$ \\ % |gk| &gash key & $\gk$ \\ % |fk| & function key & $\fk$ \\ % |st| & state & $\st$ \\ % |state| & state & $\state$ \\ % |state{myState}| & custom state & $\state{myState}$ % \end{tabular} % \end{center} % % The style in which these are displayed can be controlled via redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pckeystyle}[1]{\ensuremath{\mathsf{#1}}} \end{lstlisting} % \iffalse % % \fi % % % \amipagebreak % \section{Pseudocode} % \label{chap:pseudocode} % % \subsection{Basics} % \index{\textbackslash pseudocode} % % The cryptocode package provides the command |\pseudocode| for typesetting algorithms. % Consider the following definition of an IND-CPA game % % \begin{pchstack}[center] % \pseudocode{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam) \\ % (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % \end{pchstack} % which is generated by % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pchstack}[center] \pseudocode{ b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{pchstack} \end{lstlisting} % \iffalse % % \fi % % First note that |\pseudocode| on its own does not space itself. For laying out % one (or multiple) code blocks cryptocode % defines stacking environemnts such as |\pchstack| and |\pcvstack| that we discuss % in Section~\ref{chap:stacking}. Wrapping a single pseudocode in a |\pchstack| % as in the above example generates a nicely offset code block. % % \medskip % As code blocks are most often not used in flow text, cryptocode offers the shorthand % |\pseudocodeblock| which centers and offsets a pseudocode block as above. We thus % get the very same by writing % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % % We can also define custom block commands, for example, the following defines % a command |\pcb| that offsets and centers code and draws a tight fitting box around the code block: % \iffalse %<*example> % \fi \begin{lstlisting} \createpseudocodeblock{pcb}{center,boxed}{}{}{} \end{lstlisting} % \iffalse % % \fi % (We discuss creating custom pseudocode commands in detail in Section~\ref{sec:custom:pc:command}). % If we now use |\pcb| as just defined in the above example, we obtain the following % nicely spaced and boxed result. % \pcb{ % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam) \\ % (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % which is generated as % \iffalse %<*example> % \fi \begin{lstlisting} \pcb{ b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % % \textbf{Remark. } In the following we will use this boxed representation for the examples, but % use |\pseudocodeblock| in the corresponding code listings. % % \medskip % As you can see, the pseudocode command provides a math based environment where you can simply start typing your pseudocode % separating lines by |\\|. % % % % \subsubsection{Customizing Pseudocode} % \index{lnstart} % \index{head} % \index{lnstartright} % \index{linenumbering} % \index{syntaxhighlight} % \index{keywords} % \index{keywordsindent} % \index{codesize} % \index{keywordsunindent} % \index{keywordsuninindent} % \index{addkeywords} % \index{altkeywords} % \index{mode} % \index{space} % \index{xshift} % \index{colsep} % \index{addtolength} % \index{nodraft} % \index{yshift} % \index{bodylinesep} % \index{headlinesep} % \index{jot} % \index{beginline} % \index{endline} % \index{minlineheight} % \index{\textbackslash{}pcminlineheight} % % Besides the mandatory argument the |\pseudocode| command can take an optional argument which consists of a list of key=value pairs % separated by commas. % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocode[options]{body} \end{lstlisting} % \iffalse % % \fi % The following parameters are available: % \begin{description} % \item[head] % A header for the code % \item[width] % An exact width. If no width is specified, cryptocode tries to automatically compute the correct width. % \item[lnstart] % The starting line number when using line numbering. % \item[lnstartright] % The starting line number for right aligned line numberswhen using line numbering. % \item[linenumbering] % Enables line numbering. % % \item[skipfirstln] % Starts line numbering on the second line. % % \item[minlineheight] % Specify a minimum height for each line. Can be globally set by redefining |\pcminlineheight|. % % \item[syntaxhighlight] % When set to \enquote{auto} cryptocode will attempt to automatically hightlight keywords such as \enquote{for}, \enquote{foreach} % and \enquote{return}. Note that this feature should be regarded as experimental. In particular, it is rather slow. % \item[keywords] % Provide a comma separated list of keywords for automatic syntax highlighting. To customize the behavior of automatic spacing % you can provide keywords as % \begin{description} % \item[keywordsindent] % After seeing this keyword all following lines will be indented one extra level. % \item[keywordsunindent] % After seeing this keyword the current and all following lines will be unindented one extra level. % \item[keywordsuninindent] % After seeing this keyword the current line will be unindented one level. % \end{description} % \item[addkeywords] % Provide additional keywords for automatic syntax highlighting. % \item[altkeywords] % Provide a second list of keywords for automatic syntax highlighting that are highlighted differently. % \item[mode] % When set to text pseudocode will not start in math mode but in text mode. % \item[space] % Allows you to enable automatic spacing mode. If set to \enquote{keep} the spaces in the input are preserved. % If set to \enquote{auto} it will try to detect spacing according to keywords such as \enquote{if} and \enquote{fi}. % \item[codesize] % Allows to specify the fontsize for the pseudocode. Set to |\scriptsize| for a smaller size. % % \item[colspace] % Allows to insert spacing between columns. In particular this allows to also overlap columns by inserting negative space. % % \item[jot] % Allows to specify extra space between each line. Use |jot=1mm|. % % \item[beginline] % Allows to specify a macro that is placed at the beginning of each line. % % \item[endline] % Allows to specify a macro that is placed at the end of each line. % % \item[xshift] % Allows horizontal shifting % \item[yshift] % Allows horizontal shifting % % \item[headlinesep] % Specifies the distance between header and the line. By default set to 0pt which can be globally overwritten by setting length |\pcheadlinesep|. % \item[bodylinesep] % Specifies the distance between body and the line. By default set to |0.3\baselineskip| which can be globally overwritten by setting length |\pcbodylinesep|. % \item[colsep] % Defines the space between columns. % % \item[headheight] % Specifies the height of the header. By default set to 3.25ex which can be globally overwritten by setting length |\pcheadheight|. % % \item[headlinecmd] % Allows to overwrite which command is used to draw the bar below the headline. Defaults to |\hrule|. % % \item[addtolength] % Is added to the automatically computed width of the pseudocode (which does not take colsep into account). % % \item[valign] % Controls the vertical alignment of the pseudocode. Pseudocode is wrapped in a minipage environment and valign value is passed as orientation for the minipage. By default valign is set to \enquote{t}. % % \item[nodraft] % Forces syntax highlighting also in draft mode. % \end{description} % The following code % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock[linenumbering,syntaxhighlight=auto,head=Header]{ return null } \end{lstlisting} % \iffalse % % \fi % creates % \begin{center} % \pcb[linenumbering,syntaxhighlight=auto,head=Header]{ return null } % \end{center} % % \subsubsection{Customized Pseudocode Commands}\label{sec:custom:pc:command} % \index{\textbackslash procedure} % \index{\textbackslash createpseudocodecommand} % \index{\textbackslash createprocedurecommand} % % Besides the |\pseudocode| and |\pseudocodeblock| command the command |\procedure| % (and its block variant |\procedureblock| provides easy access to generate code with a header. % They take the following form % \iffalse %<*example> % \fi \begin{lstlisting} \procedure[options]{Header}{Body} \procedureblock[options]{Header}{Body} \end{lstlisting} % \iffalse % % \fi % % \subsubsection*{Examples} % \procb{$\indcpa_\enc^\adv(\secpar)$}{ % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % which is generated as % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{$\indcpa_\enc^\adv(\secpar)$}{ b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % % % \medskip % You can define customized pseudocode commands which either take one optional argument and two mandatory arguments (as the procedure command) % or one optional and one mandatory argument (as the pseudocode command). The following % \iffalse %<*example> % \fi \begin{lstlisting} \createpseudocodecommand{mypseudocode}{}{}{linenumbering} \createprocedurecommand{myprocedure}{}{}{linenumbering} \createpseudocodeblock{pcb}{center,boxed}{}{}{linenumbering} \createprocedureblock{procb}{center,boxed}{}{}{linenumbering} \end{lstlisting} % \iffalse % % \fi % creates the commands |\mypseudocode| and |\myprocedure| with line numbering always enabled as well % as the block commands |\pcb| and |\procb| also with line numbering enabled. The created commands % have an identical interface as the |\pseudocode| (resp.~|\procedure|) command. % The two arguments that we kept empty when generating the commands allows us to specify commands that are executed at the % very beginning when the command is called (first empty argument) and a prefix for the header. % For example, the command created as % \iffalse %<*example> % \fi \begin{lstlisting} \createprocedureblock{expproc}{center,boxed}{}{$\mathrm{Experiment}$\xspace}{linenumbering} \end{lstlisting} % \iffalse % % \fi % could be used as % \iffalse %<*example> % \fi \begin{lstlisting} \expproc{$\indcpa_\enc^\adv(\secpar)$}{ b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % This results in % \createprocedureblock{expproc}{center,boxed}{}{$\mathrm{Experiment}$\xspace}{linenumbering} % \expproc{$\indcpa_\enc^\adv(\secpar)$}{% % b \sample \bin \\ %(\pk,\sk) \sample \kgen(\secparam) \\ %(m_0,m_1) \sample \adv(\secparam, \pk, c) \\ %c \sample \enc(\pk,m_b) \\ %b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % % % \subsection{Indentation} % \index{indentation} % \index{\textbackslash pcind} % \index{\textbackslash t} % % In order to indent code use |\pcind| or short |\t|. You can also use customized spacing such as |\quad| or |\hspace| % when using the pseudocode command in math mode. % \pcb{ % \pcfor i = 1..10 \pcdo \\ % \pcind T[i] \sample \bin^n \\ % \pcfor i = 1..10 \pcdo \\ % \t T[i] \sample \bin^n } % which is generated as % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \pcfor i = 1..10 \pcdo \\ \pcind T[i] \sample \bin^n \\ \pcfor i = 1..10 \pcdo \\ \t T[i] \sample \bin^n } \end{lstlisting} % \iffalse % % \fi % You can specify multiple levels via the optional first argument % \iffalse %<*example> % \fi \begin{lstlisting} \t[level] % \pcind[level] \end{lstlisting} % \iffalse % % \fi % \pcb{ % \pcfor i = 1..10 \pcdo \\ % \t T[i] \sample \bin^n \\ % \t\t T[i] \sample \bin^n \\ % \t[3] T[i] \sample \bin^n \\ % \t[4] T[i] \sample \bin^n \\ % \t[5] T[i] \sample \bin^n } % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \pcfor i = 1..10 \pcdo \\ \t T[i] \sample \bin^n \\ \t\t T[i] \sample \bin^n \\ \t[3] T[i] \sample \bin^n \\ \t[4] T[i] \sample \bin^n \\ \t[5] T[i] \sample \bin^n } \end{lstlisting} % \iffalse % % \fi % % \index{\textbackslash pcindentname} % You can customize the indentation shortcut by redefining % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pcindentname}{t} \end{lstlisting} % \iffalse % % \fi % % \subsubsection*{Automatic Indentation} % The pseudocode command comes with an option \enquote{space=auto} which tries to detect the correct indentation from the use of % keywords. When it sees one of the following keywords % \iffalse %<*example> % \fi \begin{lstlisting} \pcif, \pcfor, \pcwhile, \pcrepeat, \pcforeach \end{lstlisting} % \iffalse % % \fi % it will increase the indentation starting from the next line. It will again remove the indentation on seeing % \iffalse %<*example> % \fi \begin{lstlisting} \pcfi, \pcendif, \pcendfor, \pcendwhile, \pcuntil, \pcendforeach \end{lstlisting} % \iffalse % % \fi % Additionally, on seeing % \iffalse %<*example> % \fi \begin{lstlisting} \pcelse, \pcelseif \end{lstlisting} % \iffalse % % \fi % it will remove the indentation for that particular line. Thus the following % \pcb[space=auto]{% % \pcfor a \in [10] \pcdo \\ % \pcfor a \in [10] \pcdo \\ % \pcfor a \in [10] \pcdo \\ % \pcif a = b \pcthen \\ % \text{some operation} \\ % \pcelseif a = c \pcthen \\ % \text{some operation} \\ % \pcelse \\ % \text{some default operation} \\ % \pcfi \\ % \pcendfor \\ % \pcendfor \\ % \pcendfor \\ % \pcreturn a} % can be obtained by: % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock[space=auto]{% \pcfor a \in [10] \pcdo \\ \pcfor a \in [10] \pcdo \\ \pcfor a \in [10] \pcdo \\ \pcif a = b \pcthen \\ \text{some operation} \\ \pcelseif a = c \pcthen \\ \text{some operation} \\ \pcelse \\ \text{some default operation} \\ \pcfi \\ \pcendfor \\ \pcendfor \\ \pcendfor \\ \pcreturn a} \end{lstlisting} % \iffalse % % \fi % Note that the manual indentation in the above example is not necessary for the outcome. Further note that the same % works when using automatic syntax highlighting (see Section~\ref{sec:syntaxhighlight}). % % \subsubsection*{Keep Input Indentation (experimental)} % \label{sec:keepindent} % The pseudocode package comes with an \emph{experimental} feature that preserves the spacing in the input. This can be enabled with % the option \enquote{space=keep}. % \iffalse %<*example> % \fi \begin{lstlisting} \begin{center} \pseudocode[space=keep]{% \pcfor i = 1..10 \pcdo \\ T[i] \sample \bin^n \\ T[i] \sample \bin^n \\ T[i] \sample \bin^n \\ T[i] \sample \bin^n \\ T[i] \sample \bin^n } \end{center} \end{lstlisting} % \iffalse % % \fi % This yields the following result % \begin{center} % \pseudocode[space=keep]{% % \pcfor i = 1..10 \pcdo \\ % T[i] \sample \bin^n \\ % T[i] \sample \bin^n \\ % T[i] \sample \bin^n \\ % T[i] \sample \bin^n \\ % T[i] \sample \bin^n } % \end{center} % % Note that automatic spacing only works when the |\pseudocode| command is not wrapped within another command. % Thus in order to get a frame box |\fbox{\pseudocode[space=keep]{code}}| will not work but you would need to use % an environment such as one offered by the \emph{mdframed} package ((\url{https://www.ctan.org/pkg/mdframed}). Also see % Section~\ref{sec:keepindent-problem}. % % \subsection{Textmode} % \index{text mode} % % By default pseudocode enables \LaTeX' math mode. You can change this behavior and tell the pseudocode command to interpret the content % in text mode by setting the option \enquote{mode=text}. % \begin{center} % \fbox{\pseudocode[mode=text]{% % This is \\ % \t simply text}} % \end{center} % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock[mode=text]{% This is \\ \t simply text} \end{lstlisting} % \iffalse % % \fi % % \subsection{Syntax Highlighting} % \label{sec:syntaxhighlight} % % \index{\textbackslash pcabort} % \index{\textbackslash pcfail} % \index{\textbackslash pccontinue} % \index{\textbackslash pccomment} % \index{\textbackslash pcdo} % \index{\textbackslash pcdone} % \index{\textbackslash pcelse} % \index{\textbackslash pcelseif} % \index{\textbackslash pcfi} % \index{\textbackslash pcendif} % \index{\textbackslash pcforeach} % \index{\textbackslash pcendforeach} % \index{\textbackslash pcglobvar} % \index{\textbackslash pcif} % \index{\textbackslash pcin} % \index{\textbackslash pcnew} % \index{\textbackslash pcnull} % \index{\textbackslash pcparse} % \index{\textbackslash pcrepeat} % \index{\textbackslash pcuntil} % \index{\textbackslash pcreturn} % \index{\textbackslash pcthen} % \index{\textbackslash pctrue} % \index{\textbackslash pcwhile} % \index{\textbackslash pcendwhile} % % % In the above examples we have used commands |\pcreturn| and |\pcfor| to highlight certain keywords. % Besides the \emph{pcreturn}, \emph{pcfor} and \emph{pcdo} (where the pc stands for pseudocode) that were used in the above % examples the package defines the following set of constants: % % \begin{center} % \begin{tabular}{lll} % \textbf{command} & \textbf{outcome} \\ % |\pcabort| & \pcabort\\ % |\pccontinue| & \pccontinue \\ % |\pccomment{comment}| & \pccomment{comment} \\ % |\pccomment[2em]{comment}| & \pccomment[2em]{comment} \\ % |\pclinecomment{comment}| & \pclinecomment{comment} \\ % |\pcdo| & \pcdo \\ % |\pcdone| & \pcdone \\ % |\pcfail| & \pcfail \\ % |\pcfalse| & \pcfalse \\ % |\pcif| & \pcif \\ % |\pcfi| & \pcfi \\ % |\pcendif| & \pcendif \\ % |\pcelse| & \pcelse \\ % |\pcelseif| & \pcelseif \\ % |\pcfor| & \pcfor \\ % |\pcendfor| & \pcendfor \\ % |\pcforeach| & \pcforeach \\ % |\pcendforeach| & \pcendforeach \\ % |\pcglobvar| & \pcglobvar \\ % |\pcin| & \pcin \\ % |\pcnew| & \pcnew \\ % |\pcnull| & \pcnull \\ % |\pcparse| & \pcparse \\ % |\pcrepeat{10}| & \pcrepeat{10} \\ % |\pcreturn| & \pcreturn \\ % |\pcuntil| & \pcuntil \\ % |\pcthen| & \pcthen \\ % |\pctrue| & \pctrue \\ % |\pcwhile| & \pcwhile \\ % |\pcendwhile| & \pcendwhile \\ % \end{tabular} % \end{center} % Note that |\pcdo|, |\pcin| and |\pcthen| have a leading space. This is due to their usual usage scenarios % such as % \pseudocodeblock{\pcfor i \pcin \{1,\ldots,10\}} % Furthermore all constants have a trailing space. This can be removed by adding the optional parameter [] such as % \pseudocodeblock{\pcfor i \pcin[] \{1,\ldots,10\}} % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{\pcfor i \pcin[] \{1,\ldots,10\}} \end{lstlisting} % \iffalse % % \fi % % \index{highlight keywords} % \index{emphasize|see highlight keywords} % \index{\textbackslash highlightkeyword} % In order to change the font you can overwrite the command \lstinline{\highlightkeyword} which is defined as % \iffalse %<*example> % \fi \begin{lstlisting} \newcommand{\highlightkeyword}[2][\ ]{\ensuremath{\mathbf{#2}}#1} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Automatic Syntax Highlighting (Experimental)} % The pseudocode command comes with an experimental (and rather slow) feature to automatically highlight keywords. % This can be activated via % the option \enquote{syntaxhighlight=auto}. The preset list of keywords it looks for are % \iffalse %<*example> % \fi \begin{lstlisting} for,foreach,{return },return,{ do },{ in },new,if, null, true,{until },{ to }, false,{ then},repeat,else if,elseif,while,else,done \end{lstlisting} % \iffalse % % \fi % Note that the keywords are matched with spaces and note the grouping for trailing spaces. That is, the \enquote{ do } keyword won't match within the string \enquote{don't}. % Via the option \enquote{keywords} you can provide a custom list of keywords. % Thus the following bubblesort variant (taken from \url{http://en.wikipedia.org/wiki/Bubble_sort}) % \procb[syntaxhighlight=auto]{Bubblesort(A : list of items)}{ % n \gets \mathsf{length}(A) \\ % repeat \\ % \t s \gets false \\ % \t for i = 1 to n-1 do \\ % \t\t \pclinecomment{if this pair is out of order} \\ % \t\t if A[i-1] > A[i] then \\ % \t\t\t \pclinecomment{swap them and remember something changed} \\ % \t\t\t \mathsf{swap}( A[i-1], A[i] ) \\ % \t\t\t s \gets true \\ % until \neg s } % \noindent can be typeset as % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[syntaxhighlight=auto]{Bubblesort(A : list of items)}{ n \gets \mathsf{length}(A) \\ repeat \\ \t s \gets false \\ \t for i = 1 to n-1 do \\ \t\t \pclinecomment{if this pair is out of order} \\ \t\t if A[i-1] > A[i] then \\ \t\t\t \pclinecomment{swap them and remember something changed} \\ \t\t\t \mathsf{swap}( A[i-1], A[i] ) \\ \t\t\t s \gets true \\ until \neg s } \end{lstlisting} % \iffalse % % \fi % % \index{addkeywords} % You can also define additional keywords using the \enquote{addkeywords} option. % This would allow us to specify \enquote{length} and \enquote{swap} in the above example. % \procb[syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{ % n \gets \mathsf{length}(A) \\ % repeat \\ % \t s \gets false \\ % \t for i = 1 to n-1 do \\ % \t\t \pclinecomment{if this pair is out of order} \\ % \t\t if A[i-1] > A[i] then \\ % \t\t\t \pclinecomment{swap them and remember something changed} \\ % \t\t\t \mathsf{swap}( A[i-1], A[i] ) \\ % \t\t\t s \gets true \\ % until \neg s } % can be typeset as % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{ n \gets \mathsf{length}(A) \\ repeat \\ \t s \gets false \\ \t for i = 1 to n-1 do \\ \t\t \pclinecomment{if this pair is out of order} \\ \t\t if A[i-1] > A[i] then \\ \t\t\t \pclinecomment{swap them and remember something changed} \\ \t\t\t \mathsf{swap}( A[i-1], A[i] ) \\ \t\t\t s \gets true \\ until \neg s } \end{lstlisting} % \iffalse % % \fi % We can also combine automatic syntax highlighting with automatic spacing in which case we need % to insert \enquote{group end} keywords: % \procb[space=auto,syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{ % n \gets length(A) \\ % repeat \\ % s \gets false \\ % for i=1 to n-1 do \\ % \pclinecomment{assuming this pair is out of order} \\ % if A[i-1]>A[i] then \\ % \pclinecomment{swap them and remember something changed} \\ % swap(A[i-1], A[i]) \\ % s \gets true \\ % endif \\ % endfor \\ % until \neg s } % % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[space=auto,syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{ n \gets length(A) \\ repeat \\ s \gets false \\ for i=1 to n-1 do \\ \pclinecomment{assuming this pair is out of order} \\ if A[i-1]>A[i] then \\ \pclinecomment{swap them and remember something changed} \\ swap(A[i-1], A[i]) \\ s \gets true \\ endif \\ endfor \\ until \neg s } \end{lstlisting} % \iffalse % % \fi % % \subsubsection*{Alternative Keywords} % \index{altkeywords} % There is a second keyword list that you can add keywords to which are highlighted not via |\highlightkeyword| but via |\highlightaltkeyword| % where alt stands for alternate. This allows you to have two different keyword styles which are by default defined as % \iffalse %<*example> % \fi \begin{lstlisting} \newcommand{\highlightkeyword}[2][\ ]{\ensuremath{\mathbf{#2}}#1} \newcommand{\highlightaltkeyword}[1]{\ensuremath{\mathsf{#1}}} \end{lstlisting} % \iffalse % % \fi % This allows you to rewrite the above example and emphasize the different nature of swap and length. % \procb[space=auto,syntaxhighlight=auto,altkeywords={swap,length}]{Bubblesort(A : list of items)}{ % n \gets length(A) \\ % repeat \\ % s \gets false \\ % for i=1 to n-1 do \\ % \pclinecomment{assuming this pair is out of order} \\ % if A[i-1]>A[i] then \\ % \pclinecomment{swap them and remember something changed} \\ % swap(A[i-1], A[i]) \\ % s \gets true \\ % endif \\ % endfor \\ % until \neg s } % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[space=auto,syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{ n \gets length(A) \\ repeat \\ s \gets false \\ for i=1 to n-1 do \\ \pclinecomment{assuming this pair is out of order} \\ if A[i-1]>A[i] then \\ \pclinecomment{swap them and remember something changed} \\ swap(A[i-1], A[i]) \\ s \gets true \\ endif \\ endfor \\ until \neg s } \end{lstlisting} % \iffalse % % \fi % % \subsubsection*{Draft Mode} % \index{nodraft} % \index{performance} % \index{draft mode} % Automatic syntax highlighting is a somewhat expensive operation as it requires several rounds of regular expression matching. % In order to speed up compilation the pseudocode command will not attempt automatic highlighting when the document is in draft mode. % When in draft mode and you want to force a specific instance of |\pseudocode| to render the code with automatic syntax % highlighting you can use the option |nodraft|. % % % \subsection{Line Numbering} % \index{line numbering} % \index{\textbackslash pcln} % \index{\textbackslash pclnr} % \index{\textbackslash pcrln} % The pseudocode command allows to insert line numbers into pseudocode. % You can either manually control line numbering or simply turn on the option % |linenumbering|. % \procb[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % \label{my:line:label} (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % is generated by % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ \label{my:line:label} (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % Note that you can use labels. In the above example |\label{my:line:label}| points to~\ref{my:line:label}. % % \subsubsection{Skipping Line Numbers} % \index{skipfirstln} % \index{\textbackslash pcskipln} % % When using automatic line numbering, you can skip line numbers by inserting a |\pcskipln| command. % This causes the line number on the \emph{next line} to be supressed. In order to suppress the first % line number use the option |skipfirstln|. Thus the following % \pcb[linenumbering,skipfirstln,mode=text]{ % \pclinecomment{Some comment on first line} \\ % Some code \pcskipln\\ % \pclinecomment{Some other comment } \\ % Some code } % is generated by % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock[linenumbering,skipfirstln,mode=text]{ \pclinecomment{Some comment on first line} \\ Some code \pcskipln\\ \pclinecomment{Some other comment } \\ Some code } \end{lstlisting} % \iffalse % % \fi % % % \subsubsection{Manually Inserting Line Numbers} % In order to manually insert line numbers use the command |\pcln|. % \procb{$\indcpa_\enc^\adv(\secparam)$}{% % \pcln b \sample \bin \\ % \pcln (\pk,\sk) \sample \kgen(\secparam) \\ % \pcln\label{my:line:label2} (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % \pcln c \sample \enc(\pk,m_b) \\ % \pcln b' \sample \adv(\secparam, \pk, c) \\ % \pcln \pcreturn b = b' } % is generated by % \iffalse %<*example> % \fi \begin{lstlisting} \procedure{$\indcpa_\enc^\adv(\secparam)$}{ \pcln b \sample \bin \\ \pcln (\pk,\sk) \sample \kgen(\secparam) \\ \pcln\label{my:line:label2} (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ \pcln c \sample \enc(\pk,m_b) \\ \pcln b' \sample \adv(\secparam, \pk, c) \\ \pcln \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % Note that labels also work when manually placing line numbers. In the above example % label \emph{my:line:label2} points to line number~\ref{my:line:label2}. % % % % \subsubsection{Start Values} % You can specify the start value (minus one) of the counter by setting the option |lnstart|. % \iffalse %<*example> % \fi \begin{lstlisting} \procedure[lnstart=10,linenumbering]{Header}{Body} \end{lstlisting} % \iffalse % % \fi % \procb[lnstart=10,linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % % \subsubsection{Separators} % \index{\textbackslash pclnseparator} % The command |\pclnseparator| defines the separator between code and line number. By % default the left separator is set to (:) colon. Also see Section~\ref{sec:protocol:separator}. % % \subsubsection{Style} % \index{\textbackslash pclnstyle} % The style in which line numbers are set can be controlled by redefining |\pclnstyle|. % % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand\pclnstyle[1]{\text{\scriptsize#1}} \end{lstlisting} % \iffalse % % \fi % For example, to set line numbers in normal font and dot separated use % % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pclnstyle}[1]{\text{#1}} \renewcommand{\pclnseparator}{.} \end{lstlisting} % \iffalse % % \fi % % { % \renewcommand{\pclnstyle}[1]{\text{#1}} % \renewcommand{\pclnseparator}{.} % \procb[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' }} % % % \subsection{Subprocedures} % \index{subprocedure} % The pseudocode package allows the typesetting of subprocedures such as % % \procb[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \begin{subprocedure}% % \dbox{\procedure{$\adv(\secparam, \pk, c)$}{% % \text{Step 1} \\ % \text{Step 2} \\ % \pcreturn m_0, m_1 }} % \end{subprocedure} \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % % To create a subprocedure use the |subprocedure| environment. The above example is generated via % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ (m_0,m_1) \sample \begin{subprocedure}% \dbox{\procedure{$\adv(\secparam, \pk, c)$}{% \text{Step 1} \\ \text{Step 2} \\ \pcreturn m_0, m_1 }} \end{subprocedure} \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % Here the dbox command (from the dashbox package) is used to generate a dashed box around the sub procedure. % % \subsubsection{Numbering in Subprocedures} % As subprocedures are simply normal pseudocode blocks, you can use easily add line numbers. % By default the line numbering starts with 1 in a subprocedure while % ensuring that the outer numbering remains intact. Also note that the linenumbering on the outer procedure in the above example is inherited % by the subprocedure. For more control, either use manual numbering or set the % option \enquote{linenumbering=off} on the |\pseudocode| command within the subprocedure. % % % % \subsection{Stacking Procedures}\label{chap:stacking} % You can stack procedures horizontally or vertically using the environments \enquote{pchstack} and \enquote{pcvstack}. % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pchstack}[options] body \end{pchstack} \begin{pcvstack}[options] body \end{pcvstack} \end{lstlisting} % \iffalse % % \fi % % The following example displays two procedures next to one another. To space two horizontally outlined procedures % use the |space| option or manually insert spaces via |\pchspace| which takes an optional length as a parameter. % % \begin{pchstack}[boxed,center,space=1em] % \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{ % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % % \procedure[linenumbering,mode=text]{Oracle $O$}{ % Some code \\ % Some more code % } % \end{pchstack} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pchstack}[boxed,center,space=1em] \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } % alternatively use \pchspace for spacing \procedure[linenumbering,mode=text]{Oracle $O$}{% Some code \\ Some more code } \end{pchstack} \end{lstlisting} % \iffalse % % \fi % % Similarly you can stack two procedures vertically using the \enquote{pcvstack} environment. As a spacing % between two vertically stacked procedures again use either the |space| option or % insert space manually via |\pcvspace| which takes an optional length as a parameter. % % \begin{pcvstack}[boxed,center,space=0.5em] % \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % % \procedure[linenumbering,mode=text]{Oracle $O$}{ % Some code \\ % Some more code % } % \end{pcvstack} % % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pcvstack}[boxed,center,space=0.5em]] \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } % alternatively use \pcvspace for spacing \procedure[linenumbering,mode=text]{Oracle $O$}{% Some code \\ Some more code } \end{pcvstack} \end{lstlisting} % \iffalse % % \fi % % Horizontal and vertical stacking can be combined % \begin{pcvstack}[boxed,center,space=1em] % % \begin{pchstack}[space=2em,center] % \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % % \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % \end{pchstack} % % \begin{pchstack}[space=0.25em] % \procedure[linenumbering,mode=text]{Oracle $O$}{ % Some code \\ % Some more code % } % % \procedure[linenumbering,mode=text]{Oracle $H_1$}{ % Some code \\ % Some more code % } % % \procedure[linenumbering,mode=text]{Oracle $H_2$}{ % Some code \\ % Some more code % } % \end{pchstack} % \end{pcvstack} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pcvstack}[boxed,center,space=1em] \begin{pchstack}[center,space=2em] \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{ b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } % alternatively use \pchspace for spacing \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{pchstack} % alternatively use \pcvspace for spacing \begin{pchstack}[space=0.25em] \procedure[linenumbering,mode=text]{Oracle $O$}{ Some code \\ Some more code } \procedure[linenumbering,mode=text]{Oracle $H_1$}{ Some code \\ Some more code } \procedure[linenumbering,mode=text]{Oracle $H_2$}{ Some code \\ Some more code } \end{pchstack} \end{pcvstack} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Stacking Options} % \index{center} % \index{boxed} % \index{space} % \index{noindent} % \index{aboveskip} % \index{belowskip} % % The following keys are available on both |pchstack| and |pcvstack| environments % \begin{description} % \item[center] % Centers the stack. % % \item[boxed] % Draws a box around the stack. % % \item[space] % Controls the space between two pseudocode blocks within a stack. The default is 0pt % which can be adapted globally by redefining |\pchstackspace| or |\pcvstackspace|. % % \item[noindent] % Does not indent the stack. Only applies if option |center| is not used. % % \item[inline] % Ensures that no paragraph is added by |pchstack|. This cannot be used together with either |center| or |noindent|. % % \item[aboveskip] % By default the outer most stack adds vertical space above. The default space added % is |\abovedisplayskip| and can be adapted by redefining |\pcaboveskip|. % % \item[belowskip] % By default the outer most stack adds vertical space below. The default space added % is |\belowdisplayskip| and can be adapted by redefining |\pcbelowskip|. Note that % the defualt space below will not be added when used in a floating environment such as a figure. % However, when manually setting belowskip it will always be added. % \end{description} % % \subsection{Default Arguments} % \index{\textbackslash pcsetargs} % \index{\textbackslash pcsethstackargs} % \index{\textbackslash pcsetvstackargs} % % You can set the default arguments to be used with pseudocode blocks via |\pcsetargs|. % This is especially handy in stacking environments to add arguments to all enclosed % code blocks. % \begin{pchstack}[space=1em,center,boxed] % \renewcommand\pclnstyle[1]{#1} % \pcsetargs{linenumbering,mode=text,minlineheight=1cm,codesize=\Large{}} % \procedure{Some Procedue A}{% % Step 1\\ % Step 2 } % %\procedure{Some Procedue B}{% %\text{Step 1}\\ %\scriptsize$\begin{pcmbox}\begin{pmatrix} A \\ B + C \end{pmatrix}\end{pcmbox}$\\ %\text{Step 3}} % % %\procedure{Some Procedue C}{ % Step 1\\ % Step 2 } % % \end{pchstack} % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pchstack}[space=1em,center,boxed] % Do not change size to scriptsize for line numbers \renewcommand\pclnstyle[1]{#1} % set default arguments for all pseudocode blocks in this hstack \pcsetargs{linenumbering,mode=text,minlineheight=1cm,codesize=\Large{}} \procedure{Some Procedue A}{ Step 1\\ Step 2 } \procedure{Some Procedue B}{ \text{Step 1}\\ \scriptsize$\begin{pcmbox}\begin{pmatrix}A \\ B + C \end{pmatrix}\end{pcmbox}$\\ \text{Step 3}} \procedure{Some Procedue C}{ Step 1\\ Step 2 } \end{pchstack} \end{lstlisting} % \iffalse % % \fi % % \subsubsection*{Default Arguments for Stacking} % Similarly to |\pcsetargs| you can define default arguments for |hstack| and |vstack| % environments via |\pcsethstackargs| and |\pcsetvstackargs|. % % \subsection{Divisions and Linebreaks} % \index{linebreaks} % \index{\textbackslash hline} % Within the pseudocode command you generate linebreaks as |\\|. In order to specify the linewidth you can add an optional argument % \iffalse %<*example> % \fi % \begin{lstlisting} \\[height] \end{lstlisting} % \iffalse % % \fi % Furthermore, you can add horizontal lines by using the second optional argument and write % \iffalse %<*example> % \fi \begin{lstlisting} \\[][\hline] \end{lstlisting} % \iffalse % % \fi % % \procb[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{ % b \sample \bin \\[2\baselineskip][\hline\hline] % (\pk,\sk) \sample \kgen(\secparam) \\ % (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c) \\ % \pcreturn b = b' } % % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\[2\baselineskip][\hline\hline] (\pk,\sk) \sample \kgen(\secparam) \\ (m_0,m_1) \sample \adv^O(\secparam, \pk) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c) \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Optimizing Layout} % % In case you are laying out multiple procedures horizontally, procedures may be slightly % misaligned if the procedure headings are not of the same height. As an example, Consider % the following setup % %\begin{pchstack}[center,space=1ex] %\procedure[linenumbering]{Procedure $A$}{ %\text{do}\\ %\text{some} \\ %\text{work} %} % %\procedure[linenumbering]{Procedure $B^{F^{h^*}}_{G_1}$}{ %\text{do}\\ %\text{some} \\ %\text{work} %} %\end{pchstack} % % Here the sub and double superscripts in Procedure $B$ make the header slightly larger than % the maximum alotted space provided for headers which causes procedure $B$ to be slightly % shifted to the bottom. The best way to remedy such a situation is to use a combination % of the |headheight| and |headlinesep| properties to increase the header space in both procedures % and shift back the headline for a more compact visualization. As we here want to set some % arguments for all procedure blocks within the stacking environment we can use |\pcsetargs|. % %\begin{pchstack}[center,space=1ex] %\pcsetargs{headheight=5ex,headlinesep=-1ex} % %\procedure[linenumbering]{Procedure $A$}{ %\text{do}\\ %\text{some} \\ %\text{work} %} % %\procedure[linenumbering]{Procedure $B^{F^{h^*}}_{G_1}$}{ %\text{do}\\ %\text{some} \\ %\text{work} %} %\end{pchstack} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pchstack}[center,space=1ex] \pcsetargs{headheight=5ex,headlinesep=-1ex} \procedure[linenumbering]{Procedure $A$}{ \text{do}\\ \text{some} \\ \text{work} } \procedure[linenumbering]{Procedure $B^{F^{h^*}}_{G_1}$}{ \text{do}\\ \text{some} \\ \text{work} } \end{pchstack} \end{lstlisting} % \iffalse % % \fi % % \subsection{Matrices and Math Environments within Pseudocode} % % In order to work its magic, cryptocode (in particular within the \lstinline{\pseudocode} command) mingles with a few low level commands such as % \lstinline{\\} or \lstinline{\halign}. The effect of this is, that when you use certain math environments, for example, to create matrices, within pseudocode % the result may be unexpected. Consider the following example % % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \text{compute } P = \begin{pmatrix} A \\ B + C \end{pmatrix} } \end{lstlisting} % \iffalse % % \fi % which, somewhat unexpectedly, yields % \pcb{ % \text{compute } P = \begin{pmatrix} % A \\ B + C % \end{pmatrix} % } % % Here, the alignment is somewhat off. In order, to allow for the \emph{pmatrix} environment % to properly work without interference from |\pseudocode| % you can wrap it into a |pcmbox| environment (where pcmbox is short for pseudocode math box). % This ensures that the low-level changes introduced by |\pseudocode| are not active. % % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \text{compute } P = \begin{pcmbox}\begin{pmatrix} A \\ B + C \end{pmatrix}\end{pcmbox} } \end{lstlisting} % \iffalse % % \fi % % \begin{center} % \fbox{ % \pseudocode{ % \text{compute } P = \begin{pcmbox}\begin{pmatrix} % A \\ B + C % \end{pmatrix}\end{pcmbox} % } % } % \end{center} % % \subsection{Fancy Code with Overlays} % % Consider the \indcpa\ game. Here we have a single adversary $\adv$ that is called twice, first to output two messages and % which is then given the ciphertext of one of the messages in order to \enquote{guess} which one was encrypted. % Often this is not visualized. % Sometimes an additional state $\state$ is passed as we have in the following example on the left. On the right, % we visualize the same idea in a slightly more fancy way. % % \begin{pchstack}[center,space=1cm] % % \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam) \\ % (\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \pcnode{start} \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c, \state) \pcnode{end} \\ % \pcreturn b = b' } % % \begin{pcimage} % \procedure[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam) \\ % (m_0,m_1) \sample \adv(\secparam, \pk, c) \pcnode{start} \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c, \state) \pcnode{end} \\ % \pcreturn b = b' } % % \pcdraw{ % \path[->] (start) edge[bend left=50] node[right]{$\state$} (start|-end); % } % \end{pcimage} % \end{pchstack} % % The image on the right is generated by: % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pcimage} \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (m_0,m_1) \sample \adv(\secparam, \pk, c) \pcnode{start} \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c, \state) \pcnode{end} \\ \pcreturn b = b' } \pcdraw{ \path[->] (start) edge[bend left=50] node[right]{$\state$} (start|-end); } \end{pcimage} \end{lstlisting} % \iffalse % % \fi % % In order to achieve the above effect cryptocode utilizes TIKZ underneath. The % |\pcnode| command generates TIKZ nodes and additionally we wrapped the % pseudocode (or procedure) command in an |\begin{pcimage}\end{pcimage}| environment % which allows us to utilize these nodes later, for example using the |\pcdraw| % command. We can achieve a similar effect without an additional pcimage environment by % using the optional argument of |\pcnode| for the TIKZ code. % % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam) \\ (m_0,m_1) \sample \adv(\secparam, \pk, c) \pcnode{start} \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c, \state) \pcnode{end}[draw={ \path[->] (start) edge[bend left=50] node[right]{$\state$} (start|-end); }] \\ \pcreturn b = b' } \end{lstlisting} % \iffalse % % \fi % % \subsubsection*{Example: Explain your Code} % As an exmaple of what you can do with this, let us put an explanation to a line of the code. % % \begin{pcimage} % \procb[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% % b \sample \bin \\ % (\pk,\sk) \sample \kgen (\secparam)\pcnode{kgen} \\ % (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ % c \sample \enc(\pk,m_b) \\ % b' \sample \adv(\secparam, \pk, c, \state) \\ % \pcreturn b = b' } % % \pcdraw{ % \node[rectangle callout,callout absolute pointer=(kgen),fill=orange] % at ([shift={(+3,+1)}]kgen) { % \begin{varwidth}{3cm} % $\kgen(\secparam)$ samples a public key $\pk$ and a private key $\sk$. % \end{varwidth} % }; % } % \end{pcimage} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{pcimage} \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secparam)$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen (\secparam)\pcnode{kgen} \\ (m_0,m_1) \sample \adv(\secparam, \pk, c) \\ c \sample \enc(\pk,m_b) \\ b' \sample \adv(\secparam, \pk, c, \state) \\ \pcreturn b = b' } \pcdraw{ \node[rectangle callout,callout absolute pointer=(kgen),fill=orange] at ([shift={(+3,+1)}]kgen) { \begin{varwidth}{3cm} $\kgen(\secparam)$ samples a public key $\pk$ and a private key $\sk$. \end{varwidth} }; } \end{pcimage} \end{lstlisting} % \iffalse % % \fi % % \amipagebreak % \section{Tabbing Mode} % \label{chap:tabbing} % \index{\&} % \index{Tabbing Mode} % \index{\textbackslash\textlangle{}} % \index{\textbackslash\textrangle{}} % In the following section we discuss how to create multiple columns within a |\pseudocode| command. % Within a |\pseudocode| command you can switch to a new column by inserting a |\>|. % This is similar to using an |align| environment and placing a tabbing character (\&). Also, % similarly to using |align| you should ensure that the number of |\>| are identical % on each line. % \pcb{% % \textbf{First} \> \textbf{Second} \> \textbf{Third} \> \textbf{Fourth} \\ % b \sample \bin \> b \sample \bin \> b \sample \bin \> b \sample \bin} % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \textbf{First} \> \textbf{Second} \> \textbf{Third} \> \textbf{Fourth} \\ b \sample \bin \> b \sample \bin \> b \sample \bin \> b \sample \bin} \end{lstlisting} % \iffalse % % \fi % As you can see the first column is left aligned the second right, the third left and so forth. % In order to get only left aligned columns you could thus simply always skip a column by % using |\>\>|. You can also use |\<| a shorthand for |\>\>|. % \pcb{% % \textbf{First} \< \textbf{Second} \< \textbf{Third} \< \textbf{Fourth} \\ % b \sample \bin \< b \sample \bin \< b \sample \bin \< b \sample \bin} % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \textbf{First} \< \textbf{Second} \< \textbf{Third} \< \textbf{Fourth} \\ b \sample \bin \< b \sample \bin \< b \sample \bin \< b \sample \bin} \end{lstlisting} % \iffalse % % \fi % % \paragraph{Column Spacing} % \index{colsep} % \index{addtolength} % You can control the space between columns using the option \enquote{colsep=2em}. Note that when doing so you should % additionally use \enquote{addtolength=5em} (where 5em depends on the number of columns) in order to avoid having % overfull hboxes. % \pcb[colsep=1em,addtolength=10em]{% % \textbf{First} \< \textbf{Second} \< \textbf{Third} \< \textbf{Fourth} \\ % b \sample \bin \< b \sample \bin \< b \sample \bin \< b \sample \bin} % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock[colsep=1em,addtolength=10em]{% \textbf{First} \< \textbf{Second} \< \textbf{Third} \< \textbf{Fourth} \\ b \sample \bin \< b \sample \bin \< b \sample \bin \< b \sample \bin} \end{lstlisting} % \iffalse % % \fi % % This is basically all you need to know in order to go on to writing protocols with the % cryptocode package. So unless you want to know a bit more about tabbing (switching columns) % and learn some of the internals, feel free to proceed to Section~\ref{chap:protocols}. % % \subsection{Tabbing in Detail} % \index{mintabmode} % At the heart of the pseudocode package is an align (or rather a flalign*) environment which allows you to use basic math notation. % Usually an align (or flalign) environment uses \& as tabbing characters. % The pseudocode comes in two modes the first of which changes the default align behavior. % That is, it automatically adds a tabbing character to the beginning and end of each line % and changes the tabbing character to |\>|. This mode is called \emph{mintabmode} and is active by default. % % In mintabmode in order to make use of extra columns in the align environment % (which we will use shortly in order to write protocols) you can use |\>| as you would use \& normally. % But, don't forget that there is an alignment tab already placed at the beginning and end of each line. So the following example % \pcb{% % \textbf{Alice} \> \> \textbf{Bob} \\ % b \sample \bin \> \> \\ % \> \xrightarrow{\text{send over } b} \> \\ % \> \> \text{do something}} % is generated by % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocodeblock{ \textbf{Alice} \> \> \textbf{Bob} \\ b \sample \bin \> \> \\ \> \xrightarrow{\text{send over } b} \> \\ \> \> \text{do something}} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Overriding The Tabbing Character} % \index{\textbackslash pctabname} % If you don't like |\>| as the tabbing character you can choose a custom command by overwriting |\pctabname|. % For example % \iffalse %<*example> % \fi \begin{lstlisting} \renewcommand{\pctabname}{\myTab} \pseudocode{ \textbf{Alice} \myTab \myTab \textbf{Bob} \\ b \sample \bin \myTab \myTab \\ \myTab \xrightarrow{\text{send over } b} \myTab \\ \myTab \myTab \text{do something}} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Custom Line Spacing and Horizontal Rules} % \index{\textbackslash pclb} % As explained, underlying the pseudocode command is an flalign environment. This would allow the use % of |\\[spacing]| to specifiy the spacing between two lines or of |[\\\hline]| % to insert a horizontal rule. In order to achieve the same effect within the pseudocode command you % can use |\\[spacing][\hline]|. You can also use |\pclb| to get a line break which % does not insert the additional alignment characters. % % \amipagebreak % \section{Protocols} % \label{chap:protocols} % % Using tabbing, we can use |\pseudocode| to also layout protocols such as % \procb{My Protocol}{ % \textbf{Alice} \> \> \textbf{Bob} \\ % b \sample \bin \> \> \\ % \> \xrightarrow{\text{send over } b} \> \\ % \> \> \text{do something} \\ % \> \xleftarrow{\text{send over sth. else}} \> \\ % \text{finalize} \> \>} % which is generated as % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{My Protocol}{ \textbf{Alice} \> \> \textbf{Bob} \\ b \sample \bin \> \> \\ \> \xrightarrow{\text{send over } b} \> \\ \> \> \text{do something} \\ \> \xleftarrow{\text{send over sth. else}} \> \\ \text{finalize} \> \>} \end{lstlisting} % \iffalse % % \fi % \index{\textbackslash sendmessage}% % \index{\textbackslash sendmessage*}% % \index{\textbackslash sendmessageright*} % \index{\textbackslash sendmessageright} % \index{\textbackslash sendmessageleft*} % \index{\textbackslash sendmessageleft} % In order to get nicer message arrows use the commands |\sendmessageright*{message}|, |\sendmessageleft*{message}|, and % |\sendmessagerightleft*{message}|. % All three take an additional optional argument specifying the length of the arrow and all % wrap their mandatory argument in an |aligned| environment. % \iffalse %<*example> % \fi \begin{lstlisting} \sendmessageright*[3.5cm]{message} \sendmessageleft*[3.5cm]{message} \end{lstlisting} % \iffalse % % \fi % % \procb{My Protocol}{ % \textbf{Alice} \> \> \textbf{Bob} \\ % b \sample \bin \> \> \\ % \> \sendmessageright*{\text{send over } b} \> \\ % \> \> \text{do something} \\ % \> \sendmessageleft*{\text{send over sth. else}} \> \\ % \text{finalize} \> \> } % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{My Protocol}{% \textbf{Alice} \> \> \textbf{Bob} \\ b \sample \bin \> \> \\ \> \sendmessageright*{\text{send over } b} \> \\ \> \> \text{do something} \\ \> \sendmessageleft*{\text{send over sth. else}} \> \\ \text{finalize} \> \> } \end{lstlisting} % \iffalse % % \fi % % To obtain granular control over how messages are set use the |\sendmessage| and % |\sendmessage*| commands. These take two parameters, the first being the message style % for the underlying TIKZ path (e.g., |->| for messages to the right) and the second % a key value list of arguments. The difference between the starred version and the % unstarred version is that the starred version wraps its labels in an |aligned| % environment. Following is an example, that showcases various message options. % \procedureblock{My Protocol}{ % \textbf{Alice} \> \> \textbf{Bob} \\ % b \sample \bin \> \> \\ % \> \sendmessage{->}{centercol=3,top=send over $b$,bottom=Text below,topstyle={draw,solid,yshift=0.25cm},style={dashed}} \> \\ % \> \> \text{do something} \\ % \> \sendmessage{<-}{length=8cm,top=send over sth. else} \> \\ % \> \sendmessage*{<->}{length=8cm,top={{a,b, c\\c,d, e}},bottom={foo}} \> \\ % \> \sendmessage{<->}{length=8cm,top=\pseudocode[linenumbering]{\text{you can also}\\\text{use pseudocode}},bottom={foo}} \> \\ % \text{finalize} \> \> } % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{My Protocol}{ \textbf{Alice} \> \> \textbf{Bob} \\ b \sample \bin \> \> \\ \> \sendmessage{->}{centercol=3,top=send over $b$,bottom=Text below,topstyle={draw,solid,yshift=0.25cm},style={dashed}} \> \\ \> \> \text{do something} \\ \> \sendmessage{<-}{length=8cm,top=send over sth. else} \> \\ \> \sendmessage*{<->}{length=8cm,top={{a,b, c\\c,d, e}},bottom={foo}} \> \\ \> \sendmessage{<->}{length=8cm,top=\pseudocode[linenumbering]{\text{you can also}\\\text{use pseudocode}},bottom={foo}} \> \\ \text{finalize} \> \> } \end{lstlisting} % \iffalse % % \fi % |sendmessage| and |sendmessage*| support the following options: % \begin{description} % \item[top] % The content to display on top of the arrow. % \item[bottom] % The content to display below the arrow. % \item[left] % The content to display on the left of the arrow. % \item[right] % The content to display on the right of the arrow. % \item[topstyle] % The TIKZ style to be used for the top node. % \item[bottomstyle] % The TIKZ style to be used for the bottom node. % \item[rightstyle] % The TIKZ style to be used for the right node. % \item[leftstyle] % The TIKZ style to be used for the left node. % \item[length] % The length of the arrow. % \item[style] % The style of the arrow. % \item[width] % The width of the column % \item[centercol] % Can be used to ensure that the message is displayed in the center. This should be set to the % column index. In the above example, the message column is the third column (note that there is % a column left of alice that is automatically inserted). % \end{description} % % \subsection{Tabbing} % When typesetting protocols you might find that using two tabs instead of a single tab usually provides % a better result as this ensures that all columns are left aligned. % For this you can use |\<| instead of |\>| (see Section~\ref{chap:tabbing}). % % \medskip % Following is once more the example from before but now with double tapping. % \procb{My Protocol}{ % \textbf{Alice} \< \< \textbf{Bob} \\ % b \sample \bin \< \< \\ % \< \sendmessageright*{\text{send over } b} \< \\ % \< \< \text{do something} \\ % \< \sendmessageleft*{\text{send over sth. else}} \< \\ % \text{finalize} \< \< } % % \subsection{Multiline Messages} % Using the starred send message commands you can easily generate multiline messages as the command % wraps an \emph{aligned} environment around the message. % \procb{My Protocol}{% % \textbf{Alice} \< \< \textbf{Bob} \\ % b \sample \bin \< \< \\ % \< \sendmessageright*{\text{send over } b\\ \text{second line}} \< \\ % \< \< \text{do something} \\ % \< \sendmessage*{<-}{top={\>\text{left aligned}\\ \> \text{multiline message}}} \< \\ % \text{finalize} \< \<} % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{My Protocol}{% \textbf{Alice} \< \< \textbf{Bob} \\ b \sample \bin \< \< \\ \< \sendmessageright*{\text{send over } b\\ \text{second line}} \< \\ \< \< \text{do something} \\ \< \sendmessage*{<-}{top={\>\text{left aligned}\\ \> \text{multiline message}}} \< \\ \text{finalize} \< \<} \end{lstlisting} % \iffalse % % \fi % % \textbf{Remark. } When using |\sendmessage*| the tabbing character |&| cannot be used. % Instead use the |\>| command as defined within |\pseudocode|. % % \subsubsection{Multiplayer Protocols} % % You are not limited to two players. In order to send messages skipping players % use |\sendmessagerightx| and |\sendmessageleftx|. % \iffalse %<*example> % \fi \begin{lstlisting} \sendmessagerightx[width]{columnspan}{Text} \sendmessageleftx[width]{columnspan}{Text} \end{lstlisting} % \iffalse % % \fi % % \procb{Multiparty Protocol}{ % \textbf{Alice} \< \< \textbf{Bob} \< \< \textbf{Charlie} \\ % \text{work} \< \< \< \< \\ % \< \sendmessageright{top=Work result} \< \< \< \\ % \< \< \text{work} \< \< \\ % \< \< \< \sendmessageright{top=Work result,bottom=Bottom message} \< \\ % \< \< \< \< \text{work} \\ % \< \sendmessageleftx[7cm]{8}{\text{A long message for Alice}} \< \\ % \text{finalize} \< \< \< \< } % % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{Multiparty Protocol}{% \textbf{Alice} \< \< \textbf{Bob} \< \< \textbf{Charlie} \\ \text{work} \< \< \< \< \\ \< \sendmessageright{top=Work result} \< \< \< \\ \< \< \text{work} \< \< \\ \< \< \< \sendmessageright{top=Work result,bottom=Bottom message} \< \\ \< \< \< \< \text{work} \\ \< \sendmessageleftx[7cm]{8}{\text{A long message for Alice}} \< \\ \text{finalize} \< \< \< \< } \end{lstlisting} % \iffalse % % \fi % Note that for the last message from Charlie to Alice we needed to specify the number of passed % over colums (|\sendmessageleftx[7cm]{8}{message}|). As we were passing % 4 |\<| where each creates 2 columns, the total was 8 columns. % % \subsubsection{Divisions} % You can use |\pcintertext| in order to divide protocols (or other pseudocode for that matter). % \iffalse %<*example> % \fi \begin{lstlisting} \pcintertext[dotted|center]{Division Text} \end{lstlisting} % \iffalse % % \fi % Note that in order to use the |\pcintertext| you need to use |\pclb| as the line break for the line % before. Also see Section~\ref{chap:tabbing}. % % \procb{My Protocol}{ % \textbf{Alice} \< \< \textbf{Bob} \\ % b \sample \bin \< \< \pclb % \pcintertext[dotted]{Some Division} \\ % \< \sendmessageright*{\text{send over } b} \< \\ % \< \< \text{do something} \pclb % \pcintertext[dotted]{Another Division} \\ % \< \sendmessageleft*{\text{message}} \< \\ % \text{finalize} \< \< } % % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{My Protocol}{% \textbf{Alice} \< \< \textbf{Bob} \\ b \sample \bin \< \< \pclb \pcintertext[dotted]{Some Division} \\ \< \sendmessageright*{\text{send over } b} \< \\ \< \< \text{do something} \pclb \pcintertext[dotted]{Another Division} \\ \< \sendmessageleft*{\text{message}} \< \\ \text{finalize} \< \< } \end{lstlisting} % \iffalse % % \fi % % \subsection{Line Numbering in Protocols} % Protocols can be numbered similarly to plain pseudocode. Additionally to the % |\pcln| there are the commands |\pclnr| and |\pcrln|. The first % allows you to right align line numbers but uses the same counter as % |\pcln|. The second uses a different counter. % % \procb{My Protocol}{% % \pcln \textbf{Alice} \< \< \textbf{Bob} \< \\ % \pcln b \sample \bin \< \< \< \\ % \< \sendmessageright*{\text{send over } b} \< \< \pclnr\\ % \< \< \text{do something} \< \pclnr \\ % \< \sendmessageleft*{\text{send over sth. else}} \<\< \pclnr \\ % \pcln \text{finalize} \< \< \<} % Which is generated as % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{My Protocol}{ \pcln \textbf{Alice} \< \< \textbf{Bob} \< \\ \pcln b \sample \bin \< \< \< \\ \< \sendmessageright*{\text{send over } b} \< \< \pclnr\\ \< \< \text{do something} \< \pclnr \\ \< \sendmessageleft*{\text{send over sth. else}} \<\< \pclnr \\ \pcln \text{finalize} \< \< \<} \end{lstlisting} % \iffalse % % \fi % % And using |\pcrln| we obtain: % \procb{My Protocol}{% % \pcln \textbf{Alice} \< \< \textbf{Bob} \< \\ % \pcln b \sample \bin \< \< \< \\ % \< \sendmessageright*{\text{send over } b} \<\< \pcrln\\ % \< \< \text{do something} \< \pcrln \\ % \< \sendmessageleft*{\text{send over sth. else}} \< \< \pcrln \\ % \pcln \text{finalize} \< \< \< } % This is generated as % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{My Protocol}{% \pcln \textbf{Alice} \< \< \textbf{Bob} \\ \pcln b \sample \bin \< \< \\ \< \sendmessageright*{\text{send over } b} \< \pcrln\\ \< \< \text{do something} \pcrln \\ \< \sendmessageleft*{\text{send over sth. else}} \< \pcrln \\ \pcln \text{finalize} \< \< } \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Separators} % \label{sec:protocol:separator} % The commands |\pclnseparator| and |\pcrlnseparator| define the separators between code and line number. % By default the left separator is set to (:) colon and the right separator is set to an empty string. % % \subsubsection{Spacing} % Spacings after the left separator and in front of the right separator can be controlled by % |\pclnspace| and |\pclnrspace| which are set to 1em and 0.5em, respectively. % % \subsection{Sub Protocols} % % Use the |subprocedure| environemnt to also create sub protocols. % % \procb{My Protocol}{ % \textbf{Alice} \< \< \textbf{Bob} \\ % b \sample \bin \< \< \\ % \< \sendmessageright*{\text{send over } b} \< \\ % \< \< \text{do something} \\ % \<\< \dbox{\begin{subprocedure}\procedure{Subprotocol}{ % \< \< \textbf{Charlie} \\ % \text{something more} \< \< \\ % \< \sendmessageright*[1.5cm]{\text{message}} \< \\ % \< \< \text{some processing} \\ % \< \< \text{more processing} \\ % \< \sendmessageleft*[1.5cm]{\text{message}} \< \\ % \< \sendmessageright*[1.5cm]{\text{message}} \< \\ % \< \sendmessageleft*[1.5cm]{\text{message}} \< \\ % }\end{subprocedure}} \\ % \< \sendmessageleft*{\text{send over sth. else}} \< \\ % \text{finalize} \< \< } % % \iffalse %<*example> % \fi \begin{lstlisting} \procedureblock{My Protocol}{ \textbf{Alice} \< \< \textbf{Bob} \\ b \sample \bin \< \< \\ \< \sendmessageright*{\text{send over } b} \< \\ \< \< \text{do something} \\ \<\< \dbox{\begin{subprocedure}\procedure{Subprotocol}{ \< \< \textbf{Charlie} \\ \text{something more} \< \< \\ \< \sendmessageright*[1.5cm]{\text{message}} \< \\ \< \< \text{some processing} \\ \< \< \text{more processing} \\ \< \sendmessageleft*[1.5cm]{\text{message}} \< \\ \< \sendmessageright*[1.5cm]{\text{message}} \< \\ \< \sendmessageleft*[1.5cm]{\text{message}} \< \\ }\end{subprocedure}} \\ \< \sendmessageleft*{\text{send over sth. else}} \< \\ \text{finalize} \< \< } \end{lstlisting} % \iffalse % % \fi % % \amipagebreak % \section{Game-Based Proofs} % \label{chap:gbproofs} % % \subsection{Basics} % \index{gameproof} % \index{\textbackslash \pcgame} % \index{gameprocedure} % % Besides displaying pseudocode the package also comes with commands to help presetn game-based proofs. % The |gameproof| environment wraps the pseudocode block of a game-based proof. % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gameproof} proof goes here \end{gameproof} \end{lstlisting} % \iffalse % % \fi % Within a |gameproof| environment use the command |\gameprocedure| which works similarly to the pseudocode % command and produces a heading of the form $\pcgame[\text{counter}](\secpar)$ where counter is a consecutive counter. % Thus, we can create the following setup % \begin{gameproof} % \begin{pchstack}[space=1em,center,boxed] % \gameprocedure[linenumbering,mode=text]{% % Step 1 \\ % Step 2 % } % \gameprocedure[mode=text]{% % Step 1 \\ % Step 2 % } % \end{pchstack} % \end{gameproof} % by using % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gameproof} \begin{pchstack}[space=1em,center,boxed] \gameprocedure[linenumbering,mode=text]{% Step 1 \\ Step 2 } \gameprocedure[mode=text]{% Step 1 \\ Step 2 } \end{pchstack} \end{gameproof} \end{lstlisting} % \iffalse % % \fi % % For discussing individual games, cryptocode provides the |\pcgame| command which % without argument prints \pcgame\ and with (optional) argument |\pcgame[n]| prints \pcgame[n]. % % \subsubsection{Highlight Changes} % \index{highlight game change} % \index{\textbackslash gamechange} % In order to highlight changes from one game to the next use |\gamechange|. % \begin{gameproof} % \begin{pchstack}[space=1em,center,boxed] % \gameprocedure[linenumbering,mode=text]{% % Step 1 \\ % Step 2 % } % \gameprocedure[mode=text]{% % Step 1 \\ % \gamechange{Step 2} % } % \end{pchstack} % \end{gameproof} % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gameproof} \begin{pchstack}[space=1em,center,boxed] \gameprocedure[linenumbering,mode=text]{% Step 1 \\ Step 2 } \gameprocedure[mode=text]{% Step 1 \\ \gamechange{Step 2} } \end{pchstack} \end{gameproof} \end{lstlisting} % \iffalse % % \fi % The background color can be controlled by redefining |\gamechangecolor| which by default % is defined as % \iffalse %<*example> % \fi \begin{lstlisting} \definecolor{gamechangecolor}{gray}{0.90} \end{lstlisting} % \iffalse % % \fi % % \textbf{Remark. } Note that |\gamechange| is always in text mode. % % \subsubsection{Boxed Games} % \index{\textbackslash tbxgameprocedure} % \index{\textbackslash pcbox} % Use |\tbxgameprocedure| in order to create two consecutive games where the second game is \emph{boxed}. Use % |\pcbox| to create boxed statements. %\begin{gameproof} %\begin{pchstack}[space=1em,boxed,center] % \gameprocedure[linenumbering]{ % \text{Step 1} \\ % \text{Step 2} % } % \tbxgameprocedure{ % \text{Step 1}; \pcbox{\text{Alternative step 1}} \\ % \gamechange{\text{Step 2 is different}} % } % \gameprocedure{ % \text{Step 1} \\ % \text{\gamechange{Step 2}} % } %\end{pchstack} %\end{gameproof} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gameproof} \begin{pchstack}[space=1em,boxed,center] \gameprocedure[linenumbering]{ \text{Step 1} \\ \text{Step 2} } \tbxgameprocedure{ \text{Step 1}; \pcbox{\text{Alternative step 1}} \\ \gamechange{\text{Step 2 is different}} } \gameprocedure{ \text{Step 1} \\ \text{\gamechange{Step 2}} } \end{pchstack} \end{gameproof} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Reduction Hints} % \index{\textbackslash addgamehop} % In a game based proof, in order to go from one game to the next we usually give a reduction, for example, we show that % the difference between two games is bound by the security of some pseudorandom generator $\mathsf{PRG}$. To give a hint % within the pseudocode that the difference between two games is down to ``something'' you can use the |\addgamehop| % command. % \iffalse %<*example> % \fi \begin{lstlisting} \addgamehop{startgame}{endgame}{options} \end{lstlisting} % \iffalse % % \fi % Here options allows you to specify the hint as well as the style. The following options are available % \begin{description} % \item[hint] % The hint text % \item[nodestyle] % A TIKZ style to be used for the node. % \item[pathstyle] % A TIKZ style to be used for the path. % \item[edgestyle] % A TIKZ style to be used for the edge. This defaults to \enquote{bend left}. % \end{description} % %\begin{gameproof} %\begin{pchstack}[center,space=2em,aboveskip=1.5em] % \gameprocedure[linenumbering]{ % \text{Step 1} \\ % \text{Step 2} % } % \tbxgameprocedure{ % \text{Step 1} \\ % \gamechange{\text{Step 2 is different}} % } %\end{pchstack} % %\addgamehop{1}{2}{hint=\footnotesize some hint,nodestyle=red} %\addgamehop{2}{3}{hint=\footnotesize some other hint,nodestyle=red} %\end{gameproof} % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gameproof} \begin{pchstack}[center,space=2em] \gameprocedure[linenumbering]{ \text{Step 1} \\ \text{Step 2} } \tbxgameprocedure{ \text{Step 1} \\ \gamechange{\text{Step 2 is different}} } \end{pchstack} \addgamehop{1}{2}{hint=\footnotesize some hint,nodestyle=red} \addgamehop{2}{3}{hint=\footnotesize some other hint} \end{gameproof} \end{lstlisting} % \iffalse % % \fi % The edgestyle allows you to specify how the hint is displayed. If you, for example want a straight line, rather than the curved arrow simply % use % \iffalse %<*example> % \fi \begin{lstlisting} \addgamehop{1}{2}{hint=\footnotesize some hint,edgestyle=} \end{lstlisting} % \iffalse % % \fi % % If game proofs do not fit into a single picture you can specify start and end hints using the commands % \iffalse %<*example> % \fi \begin{lstlisting} \addstartgamehop[first game]{options} \addendgamehop[last game]{options} \end{lstlisting} % \iffalse % % \fi % %\begin{gameproof} %\begin{pchstack}[center,space=2em,aboveskip=1em] % \gameprocedure[linenumbering]{ % \text{Step 1} \\ % \text{Step 2} % } % \gameprocedure{% % \text{Step 1} \\ % \gamechange{\text{Step 2 is different}} % } %\addstartgamehop{hint=\footnotesize some hint,edgestyle=} %\addgamehop{1}{2}{hint=\footnotesize some hint} %\addendgamehop{hint=\footnotesize some outgoing hint,edgestyle=} %\end{pchstack} %\end{gameproof} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gameproof} \begin{pchstack}[center,space=2em] \gameprocedure[linenumbering]{ \text{Step 1} \\ \text{Step 2} } \gameprocedure{ \text{Step 1} \\ \gamechange{\text{Step 2 is different}} } \end{pchstack} \addstartgamehop{hint=\footnotesize some hint,edgestyle=} \addgamehop{1}{2}{hint=\footnotesize some hint} \addendgamehop{hint=\footnotesize some outgoing hint,edgestyle=} \end{gameproof} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Numbering and Names} % By default the |gameproof| environment starts to count from 1 onwards. Its optional parameters allow you to specify a custom % name for the game as well as defining the starting number. % \iffalse %<*example> % \fi % \begin{lstlisting} \begin{gameproof}[options] \end{lstlisting} % \iffalse % % \fi % % The following parameters are available which, as usual, are provided in a key=value based form. % \begin{description} % \item[nr] % The starting number minus 1. Thus, when setting nr=5, the first game will be \pcgame[6]. % \item[name] % The name for the game % \item[arg] % The argument to be used for the game. % \end{description} % %\begin{gameproof}[nr=5,name=\mathsf{MyGame},arg=(1^n)] %\begin{pchstack}[center,space=2em,aboveskip=2.5em] % \gameprocedure[linenumbering]{ % \text{Step 1} \\ % \text{Step 2} } % \gameprocedure{ % \text{Step 1} \\ % \gamechange{\text{Step 2 is different}} } %\end{pchstack} % %\addstartgamehop{hint=\footnotesize some ingoing hint,edgestyle=} %\addgamehop{6}{7}{hint=\footnotesize some hint} %\addendgamehop{hint=\footnotesize some outgoing hint,edgestyle=} %\end{gameproof} % % \iffalse %<*example> % \fi % \begin{lstlisting} \begin{gameproof}[nr=5,name=\mathsf{MyGame},arg=(1^n)] \begin{pchstack}[center,space=2em] \gameprocedure[linenumbering]{ \text{Step 1} \\ \text{Step 2} } \gameprocedure{ \text{Step 1} \\ \gamechange{\text{Step 2 is different}} } \end{pchstack} \addstartgamehop{hint=\footnotesize some ingoing hint,edgestyle=} \addgamehop{6}{7}{hint=\footnotesize some hint} \addendgamehop{hint=\footnotesize some outgoing hint,edgestyle=} \end{gameproof} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Default Name and Argument} % The default name and argument are controlled via the commands |\pcgamename| and |\gameprocedurearg|. % % \begin{center} % \begin{tabular}{ll} % \textbf{Command} & \textbf{Default} \\ % |\pcgamename| & |\mathsf{Game}| \\ % |\gameprocedurearg| & |\secpar| % \end{tabular} % \end{center} % % \subsubsection{Bi-Directional Games} % \index{\textbackslash bxgameprocedure} % \index{\textbackslash addloopgamehop} % You can use the |\bxgameprocedure| to generate games for going in two directions. Use the |\addloopgamehop| % to add the gamehop in the middle. % % \vspace{1cm} % \begin{center} % \begin{gameproof} % \bxgameprocedure{4}{% % \pcln \text{Step 1}; \pcbox{Alternative} \\ % \pcln \text{Step 2} % } % \bxgameprocedure{3}{% % \text{Step 1}; \pcbox{Alternative} \\ % \gamechange{\text{Step 2 is different}} % } % \addstartgamehop{hint=\footnotesize some hint,edgestyle=} % \addgamehop{1}{2}{hint=\footnotesize some hint,edgestyle=} % \addloopgamehop{hint=\footnotesize some loop hint} % \addgamehop{2}{1}{hint=\footnotesize some hint} % \end{gameproof} % \end{center} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gameproof} \bxgameprocedure{4}{% \pcln \text{Step 1}; \pcbox{Alternative} \\ \pcln \text{Step 2} } \bxgameprocedure{3}{% \text{Step 1}; \pcbox{Alternative} \\ \gamechange{\text{Step 2 is different}} } \addstartgamehop{hint=\footnotesize some hint,edgestyle=} \addgamehop{1}{2}{hint=\footnotesize some hint,edgestyle=} \addloopgamehop{hint=\footnotesize some loop hint} \addgamehop{2}{1}{hint=\footnotesize some hint} \end{gameproof} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Styling Game Procedures} % It may come in handy to define default style arguments for the underlying pseudocode % command used by |\gameprocedure|. For this you can % define the default arguments by calling \lstinline{\setgameproceduredefaultstyle} to % for example: % % \iffalse %<*example> % \fi \begin{lstlisting} \setgameproceduredefaultstyle{beginline=\vphantom{\bin^\prg_\prg} \end{lstlisting} % \iffalse % % \fi % The default is to not set any options. % % \subsection{Game Descriptions} % Cryptocode also comes with an environment to provide textual descriptions of games such as % % \begin{gamedescription}[name=MyGame,nr=2] % \describegame % This is the third game. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis condimentum velit et orci volutpat, sed ultrices lorem lobortis. Nam vehicula, justo eu varius interdum, felis mi consectetur dolor, ac posuere nulla lacus varius diam. Etiam dapibus blandit leo, et porttitor augue lacinia auctor. % % \describegame[inhint=reduction target] % This is the fourt game. The arrow at the side indicates the reduction target. % \end{gamedescription} % % The above example is generated as % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{gamedescription}[name=MyGame,nr=2] \describegame This is the third game. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis condimentum velit et orci volutpat, sed ultrices lorem lobortis. Nam vehicula, justo eu varius interdum, felis mi consectetur dolor, ac posuere nulla lacus varius diam. Etiam dapibus blandit leo, et porttitor augue lacinia auctor. \describegame[inhint=reduction target] This is the second game. The arrow at the side indicates the reduction target. \end{gamedescription} \end{lstlisting} % \iffalse % % \fi % % The |gamedescription| environment takes an optional argument to specify name and counter (defaults to Game and 0). The command % |\describegame| starts a new game description and can allows you to provide a reduction hint using the option parameter |inhint|. % % \begin{description} % \item[inhint] Displays an ingoing arrow to denote the reduction target for this game hop. % \item[length] Allows to control the length of the arrow. \\ % \item[nodestyle] Allows to control the style of the node. \\ % \item[hint] Instead of having an ingoing arrow, this adds an outgoing arrow. \\ % \end{description} % % \amipagebreak % \section{Black-Box Reductions} % \label{chap:bbr} % \index{bbrenv} % \index{bbrbox} % \index{\textbackslash bbrinput} % \index{\textbackslash bbroutput} % % The cryptocode package comes with support for drawing basic black box reductions. A reduction % always takes the following form. % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Box Name] % The Box's content \end{bbrbox} % Commands to display communication, input output etc \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % That is, a |bbrenv| environment (where bbr is short for black-box reduction) which takes a single % |bbrbox| environment plus some additional commands. % % \medskip % Following is a simple example with a single (black)box and some code plus inputs outputs: % % \begin{bbrenv}[aboveskip=0.75cm,belowskip=0.75cm]{A} % \begin{bbrbox}[name=Box Name] % \pseudocode{ % \text{step 1} \\ % \text{step 2} \\ % \pcfor \text{some condition} \pcdo \\ % \t\text{step 3} % } % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % % \noindent This box is generated as % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}[aboveskip=1cm,belowskip=1cm]{A} \begin{bbrbox}[name=Box Name] \pseudocode{ \text{step 1} \\ \text{step 2} \\ \pcfor \text{some condition} \pcdo \\ \t\text{step 3} } \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % The commands |bbrinput| and |bbroutput| allow to specify input and output for the latest % |bbrenv| environment. The optional parameter for the |bbrenv| environment allows to specify leading and trailing space (this % may become necessary when using inputs and outputs). For this provide |aboveskip| and |belowskip| keys. % (Note that in an earlier version of cryptocode you could write |\begin{bbrenv}[1cm]{A}[1cm]|. While this format % is still supported it should be regarded deprecated.) % The single mandatory argument to the bbrenv environment needs to specify a unique identifier % (unique for the current reduction). This id is used as an internal TIKZ node name (\url{https://www.ctan.org/pkg/pgf}). % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}[options]{UNIQUE IDENTIFIER} % deprecated version \begin{bbrenv}[vspace before]{UNIQUE IDENTIFIER}[vspace after] \end{lstlisting} % \iffalse % % \fi % As we are drawing a TIKZ image, note that we can easily later customize the image using the labels that we % have specified on the way. % % \begin{bbrenv}[aboveskip=1cm,belowskip=1cm]{A} % \begin{bbrbox}[name=Box Name] % \pseudocode{ % \text{step 1} \\ % \text{step 2} \\ % \pcfor \text{some condition} \pcdo \\ % \pcind\text{step 3} % } % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % % \filldraw[fill=blue] (A.north) circle (4pt); % \filldraw[fill=blue] (A.west) circle (4pt); % \filldraw[fill=blue] (A.east) circle (4pt); % \filldraw[fill=blue] (A.south) circle (4pt); % \end{bbrenv} % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Box Name] \pseudocode{ \text{step 1} \\ \text{step 2} \\ \pcfor \text{some condition} \pcdo \\ \pcind\text{step 3} } \end{bbrbox} \bbrinput{input} \bbroutput{output} \filldraw[fill=blue] (A.north) circle (4pt); \filldraw[fill=blue] (A.west) circle (4pt); \filldraw[fill=blue] (A.east) circle (4pt); \filldraw[fill=blue] (A.south) circle (4pt); \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % The |bbrbox| takes as single argument a comma separated list of key value pairs. In the example we used % \iffalse %<*example> % \fi \begin{lstlisting} name=Box Name \end{lstlisting} % \iffalse % % \fi % to specify the label. The following options are available % % \index{namepos} % \index{namestyle} % \index{abovesep} % \index{minheight} % \index{xshift} % \index{yshift} % \begin{center} % \begin{tabular}{ll} % \textbf{Option} & \textbf{Description} \\ \hline % name & Specifies the box's label \\ % namepos & Specifies the position (left, center, right, top left, top center, top right, middle) \\ % namestyle & Specifies the style of the name \\ % abovesep & Space above box (defaults to |\baselineskip|) \\ % minheight & The minimal height \\ % addheight & Additional height at the end of the box \\ % xshift & Allows horizontal positioning \\ % yshift & Allows horizontal positioning \\ % style & allows to customize the node % \end{tabular} % \end{center} % % \subsection{Nesting of Boxes} % Boxes can be nested. For this simply insert a |bbrenv| (together with a single bbrbox) environment into an % existing bbrbox. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Box Name] % \pseudocode{ % \text{step 1} \\ % \text{step 2} \\ % \pcfor \text{some condition} \pcdo \\ % \pcind\text{step 3} % } % % \begin{bbrenv}{B} % \begin{bbrbox}[name=Inner Box] % \pseudocode{ % \text{inner step 1} \\ % \text{inner step 2} % } % \end{bbrbox} % \end{bbrenv} % % \pseudocode{ % \text{step 4} \\ % \text{step 5} % } % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Box Name] \pseudocode{ \text{step 1} \\ \text{step 2} \\ \pcfor \text{some condition} \pcdo \\ \pcind\text{step 3} } \begin{bbrenv}{B} \begin{bbrbox}[name=Inner Box] \pseudocode{ \text{inner step 1} \\ \text{inner step 2} } \end{bbrbox} \end{bbrenv} \pseudocode{ \text{step 4} \\ \text{step 5} } \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % \subsection{Messages and Queries} % \index{\textbackslash bbrmsgto} % \index{\textbackslash bbrmsgfrom} % \index{\textbackslash bbrmsgtofrom} % \index{\textbackslash bbrmsgfromto} % \index{\textbackslash bbrqryto} % \index{\textbackslash bbrqryfrom} % \index{\textbackslash bbrqrytofrom} % \index{\textbackslash bbrqryfromto} % % You can send messages and queries to boxes. For this use the commands % \iffalse %<*example> % \fi \begin{lstlisting} \bbrmsgto{options} \bbrmsgfrom{options} \bbrmsgtofrom{options}{options} \bbrmsgfromto{options}{options} \bbrqryto{options} \bbrqryfrom{options} \bbrqrytofrom{options}{options} \bbrqryfromto{options}{options} \end{lstlisting} % \iffalse % % \fi % By convention messages are on the left of boxes and queries on the right. Commands ending on |to| % make an arrow to the right while commands ending on |from| make an arrow to the left. The |options| % define how the message is drawn and consists of a key-value list. The |tofrom| and |fromto| variants % draw two messages (back and forth) that are more compactly set together. Here usually, the fist message % should be drawn on top (|top=Label|) while the second message should be drawn on the bottom (|bottom=Label|). % % \medskip % For example, to draw a message with a label on top and on the side use % \iffalse %<*example> % \fi \begin{lstlisting} \bbrmsgto{top=Top Label, side=Side Label} \end{lstlisting} % \iffalse % % \fi % If your label contains a \enquote{,} (comma), then group the label in $\{\}$ (curly brackets). % \iffalse %<*example> % \fi \begin{lstlisting} \bbrmsgto{top=Top Label, side={Side, Label}} \end{lstlisting} % \iffalse % % \fi % % Following is a complete example. Notice that cryptocode takes care of the vertical positioning. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Box Name] % \pseudocode{ % \text{step 1} \\ % \text{step 2} \\ % \pcfor \text{some condition} \pcdo \\ % \pcind\text{step 3} % } % % \begin{bbrenv}{B} % \begin{bbrbox}[name=Inner Box] % \pseudocode{ % \text{inner step 1} \\ % \text{inner step 2} % } % \end{bbrbox} % % \bbrmsgto{top={$m_0,m_1$}} % \bbrmsgfrom{top=$q$} % % \bbrqrytofrom{top={$m_0,m_1$}}{bottom=$q$} % % \end{bbrenv} % % \pseudocode{ % \text{step 4} \\ % \text{step 5} % } % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Box Name] \pseudocode{ \text{step 1} \\ \text{step 2} \\ \pcfor \text{some condition} \pcdo \\ \pcind\text{step 3} } \begin{bbrenv}{B} \begin{bbrbox}[name=Inner Box] \pseudocode{ \text{inner step 1} \\ \text{inner step 2} } \end{bbrbox} \bbrmsgto{top={$m_0,m_1$}} \bbrmsgfrom{top=$q$} \bbrqrytofrom{top={$m_0,m_1$}}{bottom=$q$} \end{bbrenv} \pseudocode{ \text{step 4} \\ \text{step 5} } \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Options} % Following is a list of all available options. Remember that underneath the reduction % commands is a TIKZ image (\url{https://www.ctan.org/pkg/pgf/}) and for each label % position (top, side, bottom) a node is generated which can be further customized % via low-level TIKZ. % % \begin{description} % \item[top] Label on top % \item[bottom] Label on the bottom % \item[side] Label on the far side of the box. For challengers and oracles, on the side of the box. % \item[oside] Label on the \enquote{other} side. % \item[topstyle] Style for label on top % \item[bottomstyle] Style for label on bottom % \item[sidestyle] Style for label on side % \item[osidestyle] Style for label on other side % \item[edgestyle] Style for edge % \item[length] Length of arrow % \item[topname] Name for node on top % \item[bottomname] Name for node on bottom % \item[sidename] Name for node on side % \item[osidename] Name for node on other side % \item[aboveskip] Space before message % \item[belowskip] Space after message % \item[fixedoffset] Ignores automatic spacing and sets the message at the provided offset from the top. % \item[fixedboffset] Ignores automatic spacing and sets the message at the provided offset from the bottom. % \item[islast] Places the message at the bottom. % \end{description} % % % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Box Name] % \pseudocode{ % \text{step 1} \\ % \text{step 2} \\ % \pcfor \text{some condition} \pcdo \\ % \pcind\text{step 3} % } % % \begin{bbrenv}{B} % \begin{bbrbox}[name=Inner Box] % \pseudocode{ % \text{inner step 1} \\ % \text{inner step 2} \\ % } % \end{bbrbox} % % \bbrmsgto{top={$m_0,m_1$},side=Side Label, bottom=$b$, length=2cm, % topstyle={draw, solid}, sidestyle={red}, bottomstyle={draw, dashed}} % % \end{bbrenv} % % \pseudocode{ % \text{step 4} \\ % \text{step 5} \\ % } % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Box Name] \pseudocode{ \text{step 1} \\ \text{step 2} \\ \pcfor \text{some condition} \pcdo \\ \pcind\text{step 3} } \begin{bbrenv}{B} \begin{bbrbox}[name=Inner Box] \pseudocode{ \text{inner step 1} \\ \text{inner step 2} \\ } \end{bbrbox} \bbrmsgto{top={$m_0,m_1$},side=Side Label, bottom=$b$, length=2cm, topstyle={draw, solid}, sidestyle={red}, bottomstyle={draw, dashed}} \end{bbrenv} \pseudocode{ \text{step 4} \\ \text{step 5} \\ } \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % % \subsubsection{First Message} % \index{\textbackslash bbrfirstmessageoffset} % The first message is offset by |\bbrfirstmessageoffset| which defaults to 1ex. % % \subsubsection{Add Space} % \index{\textbackslash bbrmsgspace} % \index{\textbackslash bbrqryspace} % If the spacing between messages is not sufficient you can use the |bbrmsgspace| and % |bbrqryspace| commands to add additional space. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Reduction] % \pseudocode{ % \text{Do something} % } % % \begin{bbrenv}{B} % % \begin{bbrbox}[name=Adversary,minheight=15ex,xshift=4cm] % % \end{bbrbox} % % \bbrmsgto{top=$m$} % \bbrmsgspace{1.5cm} % \bbrmsgfrom{top=$\sigma$} % % \bbrqryto{top=$m$} % \bbrqryspace{1cm} % \bbrqryfrom{top=$\sigma$} % % \end{bbrenv} % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ \text{Do something} } \begin{bbrenv}{B} \begin{bbrbox}[name=Adversary,minheight=15ex,xshift=4cm] \end{bbrbox} \bbrmsgto{top=$m$} \bbrmsgspace{1.5cm} \bbrmsgfrom{top=$\sigma$} \bbrqryto{top=$m$} \bbrqryspace{1cm} \bbrqryfrom{top=$\sigma$} \end{bbrenv} \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % Note that for placing a message at the bottom, |islast| or fixed offsets often allow % obtain more accurate results. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Reduction] % \pseudocode{ % \text{Do something} % } % % \begin{bbrenv}{B} % % \begin{bbrbox}[name=Adversary,minheight=15ex,xshift=4cm] % % \end{bbrbox} % % \bbrmsgto{top=$m$} % \bbrmsgfrom{top=$\sigma$,islast} % % \bbrqryto{top=$m$,fixedoffset=4ex} % \bbrqryfrom{top=$\sigma$,fixedboffset=4ex} % % \end{bbrenv} % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ \text{Do something} } \begin{bbrenv}{B} \begin{bbrbox}[name=Adversary,minheight=15ex,xshift=4cm] \end{bbrbox} \bbrmsgto{top=$m$} \bbrmsgfrom{top=$\sigma$,islast} \bbrqryto{top=$m$,fixedoffset=4ex} \bbrqryfrom{top=$\sigma$,fixedboffset=4ex} \end{bbrenv} \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % \subsubsection{Loops} % \index{\textbackslash bbrloop} % Often an adversary may send poly many queries to an oracle, or a reduction sends many queries to an adversary. % Consider the following setting % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Reduction] % \pseudocode{ % \text{Do something} % } % % \begin{bbrenv}{B} % % \begin{bbrbox}[name=Adversary,minheight=10ex,xshift=4cm] % % \end{bbrbox} % % \bbrmsgto{top=$m$,sidename=BeginLoop} % \bbrmsgfrom{top=$\sigma$,sidename=EndLoop} % % \end{bbrenv} % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ \text{Do something} } \begin{bbrenv}{B} \begin{bbrbox}[name=Adversary,minheight=10ex,xshift=4cm] \end{bbrbox} \bbrmsgto{top=$m$} \bbrmsgfrom{top=$\sigma$} \end{bbrenv} \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % First note that by specifying the minheight and xshift option we shifted the adversary box a bit to the right % and enlarged its box. Further we specified custom names for the node on the side of the two messages. We % can now use the |bbrloop| command to visualize that these two messages are exchanged $q$ many times % \iffalse %<*example> % \fi \begin{lstlisting} \bbrloop{BeginLoop}{EndLoop}{center=$q$} \end{lstlisting} % \iffalse % % \fi % The |bbrloop| command takes two node names and a config which allows you to specify if the label is % to be shown on the left, center or right. Here is the result. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Reduction] % \pseudocode{ % \text{Do something} % } % % \begin{bbrenv}{B} % % \begin{bbrbox}[name=Adversary,minheight=10ex,xshift=4cm] % % \end{bbrbox} % % \bbrmsgto{top=$m$,sidename=BeginLoop} % \bbrmsgspace{0.5cm} % \bbrmsgfrom{top=$\sigma$,sidename=EndLoop} % \bbrloop{BeginLoop}{EndLoop}{center=$q$} % % \end{bbrenv} % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ \text{Do something} } \begin{bbrenv}{B} \begin{bbrbox}[name=Adversary,minheight=10ex,xshift=4cm] \end{bbrbox} \bbrmsgto{top=$m$,sidename=BeginLoop} \bbrmsgspace{0.5cm} \bbrmsgfrom{top=$\sigma$,sidename=EndLoop} \bbrloop{BeginLoop}{EndLoop}{center=$q$} \end{bbrenv} \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % The |\bbrloop| command supports the following parameters: % \begin{description} % \item[center] % Label displayed within the loop % \item[left] % Label displayed left of the loop % \item[right] % Label displayed right of the loop % \item[centerstyle] % Style for center label % \item[leftstyle] % Style for left label % \item[rightstyle] % Style for right label % \item[clockwise] % Loop going in clockwise direction % \item[angle] % Angle of the arrows % \end{description} % % \subsubsection{Intertext} % \index{\textbackslash bbrmsgtxt} % \index{\textbackslash bbrqrytxt} % % If your reduction needs to do some extra work between queries use the |\bbrmsgtxt| % and |\bbrqrytxt| commands. % \iffalse %<*example> % \fi \begin{lstlisting} \bbrmsgtxt[options]{Text} \bbrqrytxt[options]{Text} \end{lstlisting} % \iffalse % % \fi % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Reduction] % \pseudocode{ % \text{Do something} % } % % \begin{bbrenv}{B} % % \begin{bbrbox}[name=Adversary,minheight=12ex,xshift=4cm] % % \end{bbrbox} % % \bbrmsgto{top=$m$} % \bbrmsgtxt{\pseudocode{ % do \\ % some \\ % work % }} % \bbrmsgfrom{top=$\sigma$} % % \bbrqryto{top=$m$} % \bbrqrytxt[nodestyle={draw,dashed},xshift=2cm]{\pseudocode{ % do \\ % some \\ % work % }} % \bbrqryfrom{top=$\sigma$} % % \end{bbrenv} % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ \text{Do something} } \begin{bbrenv}{B} \begin{bbrbox}[name=Adversary,minheight=12ex,xshift=4cm] \end{bbrbox} \bbrmsgto{top=$m$} \bbrmsgtxt{\pseudocode{ do \\ some \\ work }} \bbrmsgfrom{top=$\sigma$} \bbrqryto{top=$m$} \bbrqrytxt[nodestyle={draw,dashed},xshift=2cm]{\pseudocode{ do \\ some \\ work }} \bbrqryfrom{top=$\sigma$} \end{bbrenv} \end{bbrbox} \bbrinput{input} \bbroutput{output} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % \subsection{Oracles} % \index{bbroracle} % \index{hdistance} % \index{vdistance} % Each box can have one or more oracles which are drawn on the right hand side of the box. An oracle % is created similarly to a |bbrenv| environment using the |bbroracle| environment. Oracles % go behind the single |bbrbox| environment within an |bbrenv| enviornment. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Reduction] % \pseudocode{ % \text{Do something} % } % % \begin{bbrenv}{B} % \begin{bbrbox}[name=Adversary,minheight=3cm,xshift=4cm] % \end{bbrbox} % % \end{bbrenv} % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % % \begin{bbroracle}{OraA} % \begin{bbrbox}[name=Oracle 1] % \end{bbrbox} % \end{bbroracle} % % \begin{bbroracle}{OraB}[vdistance=2cm,hdistance=3cm] % \begin{bbrbox}[name=Oracle 2] % \end{bbrbox} % \end{bbroracle} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ \text{Do something} } \begin{bbrenv}{B} \begin{bbrbox}[name=Adversary,minheight=3cm,xshift=4cm] \end{bbrbox} \end{bbrenv} \end{bbrbox} \bbrinput{input} \bbroutput{output} \begin{bbroracle}{OraA} \begin{bbrbox}[name=Oracle 1] \end{bbrbox} \end{bbroracle} \begin{bbroracle}{OraB}[vdistance=2cm,hdistance=3cm] \begin{bbrbox}[name=Oracle 2] \end{bbrbox} \end{bbroracle} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % Via the option \enquote{hdistance=length} and \enquote{vdistance=length} you can control the horizontal and vertical position of the oracle. By default this value is set to 1.5cm and |\baselineskip|. % % \subsubsection{Communicating with Oracles} % \index{\textbackslash bbroracleqryfrom} % \index{\textbackslash bbroracleqryto} % \index{\textbackslash bbroracleqrytofrom} % \index{\textbackslash bbroracleqryfromto} % As oracles use the \emph{bbrbox} environment we can directly use the established ways to send messages and % queries to oracles. In addition you can use the |\bbroracleqryfrom| and |\bbroracleqryto|. % \iffalse %<*example> % \fi \begin{lstlisting} \bbroracleqryfrom{options} \bbroracleqryto{options} \bbroracleqrytofrom{options}{options} \bbroracleqryfromto{options}{options} \end{lstlisting} % \iffalse % % \fi % Here options allow you to specify where the label goes (top, bottom). In addition you can use % |\bbroracleqryspace| to generate extra space between oracle messages. Note % that oracle messages need to be added after the closing |\end{bbroracle}| command. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Reduction] % \pseudocode{ % \text{Do something} % } % % \begin{bbrenv}{B} % \begin{bbrbox}[name=Adversary,minheight=3cm,xshift=3cm] % \end{bbrbox} % % \end{bbrenv} % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % % \begin{bbroracle}{OraA} % \begin{bbrbox}[name=Oracle 1,minheight=1cm] % \end{bbrbox} % \end{bbroracle} % \bbroracleqryto{top=$m$} % \bbroracleqryfrom{top=$b$} % % \begin{bbroracle}{OraB} % \begin{bbrbox}[name=Oracle 2,minheight=1cm] % \end{bbrbox} % \end{bbroracle} % \bbroracleqrytofrom{top=$m$}{bottom=$b$} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ \text{Do something} } \begin{bbrenv}{B} \begin{bbrbox}[name=Adversary,minheight=3cm,xshift=3cm] \end{bbrbox} \end{bbrenv} \end{bbrbox} \bbrinput{input} \bbroutput{output} \begin{bbroracle}{OraA} \begin{bbrbox}[name=Oracle 1,minheight=1cm] \end{bbrbox} \end{bbroracle} \bbroracleqrytotop=$m$} \bbroracleqryfrom{top=$b$} \begin{bbroracle}{OraB} \begin{bbrbox}[name=Oracle 2,minheight=1cm] \end{bbrbox} \end{bbroracle} \bbroracleqrytofrom{top=$m$}{bottom=$b$} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % \subsection{Challengers} % \index{bbrchallenger} % \index{hdistance} % \index{vdistance} % Each box can have one or more challengers which are drawn on the left hand side of the box. Challengers % behave identically to oracles with the exception that they are to the left of the box. A challenger % is created similarly to a \emph{bbrenv} environment using the \emph{bbrchallenger} environment. Challengers % go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornment. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Adversary,minheight=2cm] % \pseudocode{ % \text{Do something} % } % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % % \begin{bbrchallenger}{ChaA} % \begin{bbrbox}[name=Challenger,minheight=2cm] % % \end{bbrbox} % \end{bbrchallenger} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Adversary,minheight=2cm] \pseudocode{ \text{Do something} } \end{bbrbox} \bbrinput{input} \bbroutput{output} \begin{bbrchallenger}{ChaA} \begin{bbrbox}[name=Challenger,minheight=2cm] \end{bbrbox} \end{bbrchallenger} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % Via the option \enquote{hdistance=length} and \enquote{vdistance=length} you can control the horizontal and vertical position of the challenger. By default this value is set to 1.5cm and |\baselineskip|. % % \subsubsection{Communicating with Challengers} % \index{\textbackslash bbrchallengerqryfrom} % \index{\textbackslash bbrchallengerqryto} % \index{\textbackslash bbrchallengerqrytofrom} % \index{\textbackslash bbrchallengerqryfromto} % As challengers use the \emph{bbrbox} environment we can directly use the established ways to send messages and % queries to oracles. In addition you can use the |\bbrchallengerqryfrom| and |\bbrchallengerqryto|. % \iffalse %<*example> % \fi \begin{lstlisting} \bbrchallengerqryfrom{options} \bbrchallengerqryto{options} \bbrchallengerqrytofrom{options}{options} \bbrchallengerqryfromto{options}{options} \end{lstlisting} % \iffalse % % \fi % Here options allow you to specify where the label goes (top, bottom). In addition you can use % |\bbrchallengerqryspace| to generate extra space between oracle messages. Note % that challenger messages need to be added after the closing |\end{bbrchallenger}| command. % % \begin{bbrenv}[aboveskip=1cm,belowskip=0.5cm]{A} % \begin{bbrbox}[name=Adversary,minheight=2cm] % \pseudocode{ % \text{Do something} % } % % \end{bbrbox} % \bbrinput{input} % \bbroutput{output} % % \begin{bbrchallenger}{ChaA} % \begin{bbrbox}[name=Challenger,minheight=2cm] % % \end{bbrbox} % \end{bbrchallenger} % % \bbrchallengerqrytofrom{top=$m$}{bottom=$b$} % \end{bbrenv} % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{A} \begin{bbrbox}[name=Adversary,minheight=2cm] \pseudocode{ \text{Do something} } \end{bbrbox} \bbrinput{input} \bbroutput{output} \begin{bbrchallenger}{ChaA} \begin{bbrbox}[name=Challenger,minheight=2cm] \end{bbrbox} \end{bbrchallenger} \bbrchallengerqryfromto{top=$m$}{bottom=$b$} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % \subsection{Examples} % A reduction sketch for full domain hash. % %\begin{bbrenv}{Red} % % \begin{bbrbox}[name=\textsc{Reduction }$\bdv$] % % \pseudocode{ % j \sample [q] % } % % \vspace{2ex} % \emph{/* begin simulation */} % % \begin{bbrenv}[aboveskip=2em]{Adv} % \begin{bbrbox}[name=$\adv$,minheight=8.5cm,style={fill=black},namestyle={color=white},xshift=3cm] % \end{bbrbox} % % \bbrinput{$\fk$} % \bbroutput{$\sigma$} % % \bbrmsgfrom{top=$m_1$,afterskip=-0.5\baselineskip} % \bbrmsgto{bottom=$\$$,afterskip=0.5\baselineskip} % % \bbrmsgvdots % % \bbrmsgfrom{top=$m_{j-1}$,beforeskip=0.5\baselineskip,afterskip=-0.5\baselineskip} % \bbrmsgto{bottom=$\$$,afterskip=1.5\baselineskip} % % \bbrmsgfrom{top=$m_j$,afterskip=-0.5\baselineskip} % \bbrmsgto{bottom=$y$,afterskip=1.5\baselineskip} % % \bbrmsgfrom{top=$m_{j+1}$,afterskip=-0.5\baselineskip} % \bbrmsgto{bottom=$\$$,afterskip=0.5\baselineskip} % % \bbrmsgvdots % % \bbrmsgfrom{top=$m_q$,beforeskip=0.5\baselineskip,afterskip=-0.5\baselineskip} % \bbrmsgto{bottom=$\$$} % % \begin{bbroracle}{Sign} % \begin{bbrbox}[name=Sign,namepos=center,style={draw},minheight=1cm] % \end{bbrbox} % \end{bbroracle} % % \bbroracleqryto{top=$m$} % \bbroracleqryfrom{top=$\sigma$} % % \end{bbrenv} % % \pcdraw{ % \node[left=2cm of Adv.north west] (startsim) {}; % \node[left=2cm of Adv.south west] (endsim) {}; % \draw[->,thick] (startsim) -- (endsim); % \node[rotate=90, left=2.75cm of Adv.west,anchor=center] () {\textsc{Simulation of Random Oracle}}; % } % % \emph{/* end simulation */} % % \pseudocode{ % y \gets \sigma % } % % \end{bbrbox} % \bbrqryfrom{beforeskip=0.25cm,top={$(\fk, y)$},side={\dbox{\pseudocode{ % \fk \sample \fash.\kgen(\secparam) \\ x \sample \bin^{\fash.\il(\secpar)} \\ y \gets \fash.\eval(\fk, x)} % }}} % \bbrqryto{beforeskip=11.75cm,side=\pseudocode{y \in \fash^{-1}(\fk, x)}} % \end{bbrenv} % % % \iffalse %<*example> % \fi \begin{lstlisting} \begin{bbrenv}{Red} \begin{bbrbox}[name=\textsc{Reduction }$\bdv$] \pseudocode{ j \sample [q] } \vspace{2ex} \emph{/* begin simulation */} \begin{bbrenv}[aboveskip=2em]{Adv} \begin{bbrbox}[name=$\adv$,minheight=8.5cm,style={fill=black},namestyle={color=white},xshift=3cm] \end{bbrbox} \bbrinput{$\fk$} \bbroutput{$\sigma$} \bbrmsgfrom{top=$m_1$,afterskip=-0.5\baselineskip} \bbrmsgto{bottom=$\$$,afterskip=0.5\baselineskip} \bbrmsgvdots \bbrmsgfrom{top=$m_{j-1}$,beforeskip=0.5\baselineskip,afterskip=-0.5\baselineskip} \bbrmsgto{bottom=$\$$,afterskip=1.5\baselineskip} \bbrmsgfrom{top=$m_j$,afterskip=-0.5\baselineskip} \bbrmsgto{bottom=$y$,afterskip=1.5\baselineskip} \bbrmsgfrom{top=$m_{j+1}$,afterskip=-0.5\baselineskip} \bbrmsgto{bottom=$\$$,afterskip=0.5\baselineskip} \bbrmsgvdots \bbrmsgfrom{top=$m_q$,beforeskip=0.5\baselineskip,afterskip=-0.5\baselineskip} \bbrmsgto{bottom=$\$$} \begin{bbroracle}{Sign} \begin{bbrbox}[name=Sign,namepos=center,style={draw},minheight=1cm] \end{bbrbox} \end{bbroracle} \bbroracleqryto{top=$m$} \bbroracleqryfrom{top=$\sigma$} \end{bbrenv} \pcdraw{ \node[left=2cm of Adv.north west] (startsim) {}; \node[left=2cm of Adv.south west] (endsim) {}; \draw[->,thick] (startsim) -- (endsim); \node[rotate=90, left=2.75cm of Adv.west,anchor=center] () {\textsc{Simulation of Random Oracle}}; } \emph{/* end simulation */} \pseudocode{ y \gets \sigma } \end{bbrbox} \bbrqryfrom{beforeskip=0.25cm,top={$(\fk, y)$},side={\dbox{\pseudocode{ \fk \sample \fash.\kgen(\secparam) \\ x \sample \bin^{\fash.\il(\secpar)} \\ y \gets \fash.\eval(\fk, x)} }}} \bbrqryto{beforeskip=11.75cm,side=\pseudocode{y \in \fash^{-1}(\fk, x)}} \end{bbrenv} \end{lstlisting} % \iffalse % % \fi % % \amipagebreak % \section{Known Issues} % % \subsection{Pseudocode KeepSpacing within Commands} % \label{sec:keepindent-problem} % \index{\textbackslash fbox} % \index{framebox} % The (experimental) \enquote{space=keep} option of pseudocode which should output spacing identical to that of the input % will fail, if the pseudocode command is called from within another command. An example is to % wrap the |\pseudocode| command in an |\fbox| or in a stacking environment such as |\pchstack|. % As a workaround for generating frame boxes you should hence % use a package such as \emph{mdframed} (\url{https://www.ctan.org/pkg/mdframed}) which provides a frame environment. % % \begin{mdframed} % \pseudocode[space=keep,mode=text]{ Pseudocode with - spaces -} % \end{mdframed} % \iffalse %<*example> % \fi \begin{lstlisting} \pseudocode[space=keep,mode=text]{ Pseudocode with - spaces -} \end{lstlisting} % \iffalse % % \fi % % As an alternative you could use a \emph{savebox} (in combination with the |lrbox| environment): % % \newsavebox{\mypcbox} % \begin{lrbox}{\mypcbox}% % \pseudocode[space=keep,mode=text]{ Pseudocode with - spaces -}% % \end{lrbox} % \fbox{\usebox{\mypcbox}} % % \iffalse %<*example> % \fi \begin{lstlisting} \newsavebox{\mypcbox} \begin{lrbox}{\mypcbox}% \pseudocode[space=keep,mode=text]{ Pseudocode with - spaces -}% \end{lrbox} \fbox{\usebox{\mypcbox}} \end{lstlisting} % \iffalse % % \fi % % \subsection{AMSFonts} % \index{amsfonts} % \index{noamsfonts|see {package options}} % \index{package options!noamsfonts} % Some packages are not happy with the \enquote{amsfonts} package. Cryptocode will attempt to load amsfonts if it is loaded % with either the \enquote{sets} or the \enquote{probability} option. In order to not load amsfonts you can additionally add the % \enquote{noamsfonts} at the very end. Note that in this case you should ensure that the command |\mathbb| is defined % as this is used by most of the commands in \enquote{sets} and some of the commands in \enquote{probability}. % % \subsection{Hyperref} % The hyperref package (\url{https://www.ctan.org/pkg/hyperref}) should be loaded before cryptocode. If this is not possible % call the |\pcfixhyperref| after |\begin{document}|. % % %\StopEventually{% % \PrintChanges % \PrintIndex %} % % % \amipagebreak %\section{Implementation} % % Following is the implementation of cryptocode. The source code documentation is % a work in progress. % % \begin{macrocode} %<*cryptocode.sty> % \end{macrocode} % % Note that most macros are prefixed with \emph{pc} % short for pseudocode. This is a general design choice to not conflict % with macros defined by other packages. One exception are the macros % defined via the various package options. % % % Load amsmath and mathtools early on, before defining various macros. % \begin{macrocode} \RequirePackage{amsmath} \RequirePackage{mathtools} % \end{macrocode} % % % \subsection{Package Options} % %\begin{macro}{\@pc@opt@amsfonts} % Definitions of boolean flags used to determin whether or not to load amsfonts. % \begin{macrocode} \newif\if@pc@opt@amsfonts % \end{macrocode} %\end{macro} % % %\begin{macro}{\@pc@opt@advantage} % Whether or not to define commands for the given option. % \begin{macrocode} \newif\if@pc@opt@advantage % \end{macrocode} %\end{macro} % % %\begin{macro}{\@pc@opt@centernot} % Whether or not to load centernot % \begin{macrocode} \newif\if@pc@opt@centernot % \end{macrocode} %\end{macro} % % % \subsubsection{operators} % %\begin{macro}{\sample} %\begin{macro}{\floor} %\begin{macro}{\tfloor} %\begin{macro}{\ceil} %\begin{macro}{\tceil} %\begin{macro}{\Angle} %\begin{macro}{\tAngle} %\begin{macro}{\abs} %\begin{macro}{\tabs} %\begin{macro}{\norm} %\begin{macro}{\tnorm} %\begin{macro}{\concat} %\begin{macro}{\emptystring} %\begin{macro}{\argmax} %\begin{macro}{\argmin} %\begin{macro}{\pindist} %\begin{macro}{\cindist} %\begin{macro}{\sindist} % Definitions of macros for the \emph{operators} pacakge option. % % \begin{macrocode} \DeclareOption{operators}{ \providecommand{\sample}{\hskip2.3pt{\gets\!\!\mbox{\scriptsize${\$}$\normalsize}}\,} \DeclarePairedDelimiter\pc@floor{\lfloor}{\rfloor} \providecommand{\floor}[1]{\pc@floor*{#1}} \providecommand{\tfloor}[1]{\pc@floor{#1}} \DeclarePairedDelimiter\pc@ceil{\lceil}{\rceil} \providecommand{\ceil}[1]{\pc@ceil*{#1}} \providecommand{\tceil}[1]{\pc@ceil{#1}} \DeclarePairedDelimiter\pc@Angle{\langle}{\rangle} \providecommand{\Angle}[1]{\pc@Angle*{#1}} \providecommand{\tAngle}[1]{\pc@Angle{#1}} \DeclarePairedDelimiter\pc@abs{\lvert}{\rvert} \providecommand{\abs}[1]{\pc@abs*{#1}} \providecommand{\tabs}[1]{\pc@abs{#1}} \DeclarePairedDelimiter\pc@norm{\lVert}{\rVert} \providecommand{\norm}[1]{\pc@norm*{#1}} \providecommand{\tnorm}[1]{\pc@tnorm{#1}} \providecommand{\concat}{\ensuremath{\|}} \providecommand{\emptystring}{\ensuremath{\varepsilon}} \DeclareMathOperator*{\argmax}{arg\,max} \DeclareMathOperator*{\argmin}{arg\,min} %indistinguishability \newcommand{\@pc@oset}[3][0ex]{% \mathrel{\mathop{#3}\limits^{ \vbox to#1{\kern-2\ex@ \hbox{$\scriptstyle#2$}\vss}}}} \newcommand{\pindist}{\@pc@oset{\text{p}}{\lower.2ex\hbox{$=$}}} \newcommand{\sindist}{\@pc@oset{\text{s}}{\lower.1ex\hbox{$\approx$}}} \newcommand{\cindist}{\@pc@oset{\text{c}}{\lower.1ex\hbox{$\approx$}}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{adversary} % %\begin{macro}{\adversary} %\begin{macro}{\adv} %\begin{macro}{\bdv} %\begin{macro}{\cdv} %\begin{macro}{\ddv} %\begin{macro}{\edv} %\begin{macro}{\mdv} %\begin{macro}{\pdv} %\begin{macro}{\rdv} %\begin{macro}{\sdv} % Definitions of adversaries $\adv$ (|\adv|), $\bdv$ (|\bdv|), etc.~together with a style |\pcadvstyle|. % \begin{macrocode} \DeclareOption{adversary}{ \providecommand{\adversary}[1]{\pcadvstyle{#1}} \providecommand{\adv}{\pcadvstyle{A}} \providecommand{\bdv}{\pcadvstyle{B}} \providecommand{\cdv}{\pcadvstyle{C}} \providecommand{\ddv}{\pcadvstyle{D}} \providecommand{\edv}{\pcadvstyle{E}} \providecommand{\mdv}{\pcadvstyle{M}} \providecommand{\pdv}{\pcadvstyle{P}} \providecommand{\rdv}{\pcadvstyle{R}} \providecommand{\sdv}{\pcadvstyle{S}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{landau} % %\begin{macro}{\bigO} %\begin{macro}{\smallO} %\begin{macro}{\bigOmega} %\begin{macro}{\smallOmega} %\begin{macro}{\bigsmallO} %\begin{macro}{\bigTheta} %\begin{macro}{\orderOf} % Defines several \emph{Landau symbols}. % \begin{macrocode} \DeclareOption{landau}{ \providecommand{\bigO}[1]{\ensuremath{\mathcal{O}\pc@olrk*{#1}}} \providecommand{\smallO}[1]{\ensuremath{\text{o}\pc@olrk*{#1}}} \providecommand{\bigOmega}[1]{\ensuremath{\Omega\pc@olrk*{#1}}} \providecommand{\smallOmega}[1]{\ensuremath{\omega\pc@olrk*{#1}}} \providecommand{\bigsmallO}[1]{% \PackageWarning{cryptocode}{bigsmallO is deprecated. Use bigTheta instead.}% \ensuremath{\Theta\pc@olrk*{#1}}} \providecommand{\bigTheta}[1]{\ensuremath{\Theta\pc@olrk*{#1}}} \providecommand{\orderOf}{\ensuremath{\sim}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{probability} % %\begin{macro}{\probname} %\begin{macro}{\expectationname} %\begin{macro}{\supportname} %\begin{macro}{\tprob} %\begin{macro}{\prob} %\begin{macro}{\tprobsub} %\begin{macro}{\probsub} %\begin{macro}{\probsublong} %\begin{macro}{\tcondprob} %\begin{macro}{\condprob} %\begin{macro}{\tcondprobsub} %\begin{macro}{\condprobsub} %\begin{macro}{\texpect} %\begin{macro}{\expect} %\begin{macro}{\texpsub} %\begin{macro}{\expsub} %\begin{macro}{\tcondexp} %\begin{macro}{\condexp} %\begin{macro}{\tcondexpsub} %\begin{macro}{\condexpsub} %\begin{macro}{\supp} %\begin{macro}{\entropy} %\begin{macro}{\condentropy} %\begin{macro}{\minentropy} %\begin{macro}{\condminentropy} %\begin{macro}{\condavgminentropy} % The \emph{probability} package option defines various macros for typesetting % probabilities. % % Sets flags |\@pc@opt@amsfontstrue|. % \begin{macrocode} \DeclareOption{probability}{ \@pc@opt@amsfontstrue \providecommand{\probname}{Pr} \providecommand{\expectationname}{\ensuremath{\mathbb{E}}} \providecommand{\supportname}{Supp} \providecommand{\tprob}[1]{\ensuremath{\operatorname{\probname}\pc@elrk{#1}}} \providecommand{\prob}[1]{\ensuremath{\operatorname{\probname}\pc@elrk*{#1}}} \providecommand{\tprobsub}[2]{\ensuremath{\operatorname{\probname}_{#1}\pc@elrk{#2}}} \providecommand{\probsub}[2]{\ensuremath{\operatorname{\probname}_{#1}\pc@elrk*{#2}}} \providecommand{\probsublong}[2]{\ensuremath{\prob{#2\,:\,#1}}} \providecommand{\tcondprob}[2]{\ensuremath{\tprob{#1\,\left|\,#2\vphantom{#1}\right.}}} \providecommand{\condprob}[2]{\ensuremath{\prob{#1\,\left|\,#2\vphantom{#1}\right.}}} \providecommand{\tcondprobsub}[3]{\ensuremath{\tprobsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} \providecommand{\condprobsub}[3]{\ensuremath{\probsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} \providecommand{\texpect}[1]{\ensuremath{\operatorname{\expectationname}\pc@elrk{#1}}} \providecommand{\expect}[1]{\ensuremath{\operatorname{\expectationname}\pc@elrk*{#1}}} \providecommand{\texpsub}[2]{\ensuremath{\operatorname{\expectationname}_{#1}\pc@elrk{#2}}} \providecommand{\expsub}[2]{\ensuremath{\operatorname{\expectationname}_{#1}\pc@elrk*{#2}}} \providecommand{\tcondexp}[2]{\ensuremath{\texpect{#1\,\left|\,#2\vphantom{#1}\right.}}} \providecommand{\condexp}[2]{\ensuremath{\expect{#1\,\left|\,#2\vphantom{#1}\right.}}} \providecommand{\tcondexpsub}[3]{\ensuremath{\texpsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} \providecommand{\condexpsub}[3]{\ensuremath{\expsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} \providecommand{\supp}[1]{\ensuremath{\operatorname{Supp}\pc@olrk*{#1}}} \providecommand{\entropy}[1]{\ensuremath{\operatorname{H}\pc@olrk*{#1}}} \providecommand{\condentropy}[2]{% \ensuremath{\operatorname{H}\pc@olrk*{#1\,\left|\,#2\vphantom{#1}\right.}}} \providecommand{\minentropy}[1]{\ensuremath{\operatorname{H_\infty}\pc@olrk*{#1}}} \providecommand{\tminentropy}[1]{\ensuremath{\operatorname{H_\infty}\pc@olrk{#1}}} \providecommand{\condminentropy}[2]{% \ensuremath{\operatorname{H_\infty}\pc@olrk*{#1\,\left|\,#2\vphantom{#1}\right.}}} \providecommand{\tcondminentropy}[2]{% \ensuremath{\operatorname{H_\infty}\pc@olrk{#1\,\left|\,#2\vphantom{#1}\right.}}} \providecommand{\condavgminentropy}[2]{% \ensuremath{\operatorname{\tilde{H}_\infty}\pc@olrk*{#1\,\left|\,#2\vphantom{#1}\right.}}} \providecommand{\tcondavgminentropy}[2]{% \ensuremath{\operatorname{\tilde{H}_\infty}\pc@olrk{#1\,\left|\,#2\vphantom{#1}\right.}}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{sets} % %\begin{macro}{\NN} %\begin{macro}{\ZZ} %\begin{macro}{\CC} %\begin{macro}{\QQ} %\begin{macro}{\RR} %\begin{macro}{\PP} %\begin{macro}{\FF} %\begin{macro}{\GG} %\begin{macro}{\set} %\begin{macro}{\sequence} %\begin{macro}{\bin} % The \emph{sets} option defines various macros for standard sets such as % natural numbers |\NN| (\NN). The style can be configured via |\pcsetstyle|. % % As we usually work with bit strings, the macro |\bin| defines the set \bin. % Sets the flags |\@pc@opt@amsfontstrue|. % \begin{macrocode} \DeclareOption{sets}{ \@pc@opt@amsfontstrue \providecommand\NN{\pcsetstyle{N}} \providecommand\ZZ{\pcsetstyle{Z}} \providecommand\CC{\pcsetstyle{C}} \providecommand\QQ{\pcsetstyle{Q}} \providecommand\RR{\pcsetstyle{R}} \providecommand\PP{\pcsetstyle{P}} \providecommand\FF{\pcsetstyle{F}} \providecommand\GG{\pcsetstyle{G}} \providecommand{\set}[1]{\ensuremath{\pc@clrk*{#1}}} \providecommand{\sequence}[1]{\ensuremath{\pc@olrk*{#1}}} \providecommand{\bin}{\ensuremath{\{0,1\}}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % % \subsubsection{noamsfonts} % %\begin{macro}{\@pc@opt@amsfontsfalse} % Package option \emph{noamsfonts} ensures that ams fonts are not loaded. % For this flag |\@pc@opt@amsfontsfalse| is set to false. % \begin{macrocode} \DeclareOption{noamsfonts}{ \@pc@opt@amsfontsfalse } % \end{macrocode} %\end{macro} % % % \subsubsection{notions} % %\begin{macro}{\indcpa} %\begin{macro}{\indcca} %\begin{macro}{\indccai} %\begin{macro}{\indccaii} %\begin{macro}{\priv} %\begin{macro}{\ind} %\begin{macro}{\indcda} %\begin{macro}{\prvcda} %\begin{macro}{\prvrcda} %\begin{macro}{\kiae} %\begin{macro}{\kdae} %\begin{macro}{\mle} %\begin{macro}{\uce} %\begin{macro}{\eufcma} %\begin{macro}{\eufko} %\begin{macro}{\eufnacma} %\begin{macro}{\seufcma} % The \emph{notion} package option defines various cryptographic security % notions. % The style to be can be defined via |\pcnotionstyle|. % \begin{macrocode} \DeclareOption{notions}{ \providecommand{\indcpa}{\pcnotionstyle{IND\pcmathhyphen{}CPA}} \providecommand{\indcca}{\pcnotionstyle{IND\pcmathhyphen{}CCA}} \providecommand{\indccai}{\pcnotionstyle{IND\pcmathhyphen{}CCA1}} \providecommand{\indccaii}{\pcnotionstyle{IND\pcmathhyphen{}CCA2}} \providecommand{\priv}{\pcnotionstyle{PRIV}} \providecommand{\ind}{\pcnotionstyle{IND}} \providecommand{\indcda}{\pcnotionstyle{IND\pcmathhyphen{}CDA}} \providecommand{\prvcda}{\pcnotionstyle{PRV\pcmathhyphen{}CDA}} \providecommand{\prvrcda}{\pcnotionstyle{PRV\$\pcmathhyphen{}CDA}} \providecommand{\kiae}{\pcnotionstyle{KIAE}} \providecommand{\kdae}{\pcnotionstyle{KDAE}} \providecommand{\mle}{\pcnotionstyle{MLE}} \providecommand{\uce}{\pcnotionstyle{UCE}} \providecommand{\eufcma}{\pcnotionstyle{EUF\pcmathhyphen{}CMA}} \providecommand{\eufnacma}{\pcnotionstyle{EUF\pcmathhyphen{}naCMA}} \providecommand{\seufcma}{\pcnotionstyle{SUF\pcmathhyphen{}CMA}} \providecommand{\eufko}{\pcnotionstyle{EUF\pcmathhyphen{}KO}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % % \subsubsection{logic} % %\begin{macro}{\AND} %\begin{macro}{\OR} %\begin{macro}{\NOR} %\begin{macro}{\NOT} %\begin{macro}{\NAND} %\begin{macro}{\XOR} %\begin{macro}{\XNOR} %\begin{macro}{\xor} %\begin{macro}{\false} %\begin{macro}{\true} %\begin{macro}{\notimplies} % \begin{macrocode} \DeclareOption{logic}{ % load centernot needed for notimplies \@pc@opt@centernottrue \providecommand{\AND}{\ensuremath{\mathrm{AND}}} \providecommand{\OR}{\ensuremath{\mathrm{OR}}} \providecommand{\NOR}{\ensuremath{\mathrm{NOR}}} \providecommand{\NOT}{\ensuremath{\mathrm{NOT}}} \providecommand{\NAND}{\ensuremath{\mathrm{NAND}}} \providecommand{\XOR}{\ensuremath{\mathrm{XOR}}} \providecommand{\XNOR}{\ensuremath{\mathrm{XNOR}}} \providecommand{\xor}{\ensuremath{\oplus}} \providecommand{\false}{\mathsf{false}} \providecommand{\true}{\mathsf{true}} \providecommand{\notimplies}{\centernot\implies} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{ff (function families)} % % %\begin{macro}{\kgen} %\begin{macro}{\pgen} %\begin{macro}{\eval} %\begin{macro}{\invert} %\begin{macro}{\il} %\begin{macro}{\ol} %\begin{macro}{\kl} %\begin{macro}{\nl} %\begin{macro}{\rl} % The \emph{ff} option defines macros for function families. % Algorithms are typeset via |\pcalgostyle|. % \begin{macrocode} \DeclareOption{ff}{ \providecommand{\kgen}{\pcalgostyle{KGen}} \providecommand{\pgen}{\pcalgostyle{Pgen}} \providecommand{\eval}{\pcalgostyle{Eval}} \providecommand{\invert}{\pcalgostyle{Inv}} \providecommand{\il}{\pcalgostyle{il}} \providecommand{\ol}{\pcalgostyle{ol}} \providecommand{\kl}{\pcalgostyle{kl}} \providecommand{\nl}{\pcalgostyle{nl}} \providecommand{\rl}{\pcalgostyle{rl}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{mm (machine models)} % % %\begin{macro}{\pcmachinemodelstyle} %\begin{macro}{\CRKT} %\begin{macro}{\TM} %\begin{macro}{\PROG} %\begin{macro}{\uTM} %\begin{macro}{\uC} %\begin{macro}{\uP} %\begin{macro}{\csize} %\begin{macro}{\tmtime} %\begin{macro}{\ppt} % The \emph{mm} option defines macros for machine models. % \begin{macrocode} \DeclareOption{mm}{ \providecommand{\CRKT}{\pcmachinemodelstyle{C}} \providecommand{\TM}{\pcmachinemodelstyle{M}} \providecommand{\PROG}{\pcmachinemodelstyle{P}} \providecommand{\uTM}{\pcmachinemodelstyle{UM}} \providecommand{\uC}{\pcmachinemodelstyle{UC}} \providecommand{\uP}{\pcmachinemodelstyle{UEval}} \providecommand{\csize}{\pcmachinemodelstyle{size}} \providecommand{\tmtime}{\pcmachinemodelstyle{time}} \providecommand{\ppt}{\pcalgostyle{PPT}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % % \subsubsection{advantage} % % The \emph{advantage} option defines an |\advantage| command for typesetting % advantage declarations of adversaries. % \begin{macrocode} \DeclareOption{advantage}{ \@pc@opt@advantagetrue } % \end{macrocode} % % % \subsubsection{primitives} % %\begin{macro}{\prover} %\begin{macro}{\verifier} %\begin{macro}{\nizk} %\begin{macro}{\hash} %\begin{macro}{\gash} %\begin{macro}{\fash} %\begin{macro}{\enc} %\begin{macro}{\dec} %\begin{macro}{\sig} %\begin{macro}{\sign} %\begin{macro}{\verify} %\begin{macro}{\obf} %\begin{macro}{\iO} %\begin{macro}{\diO} %\begin{macro}{\owf} %\begin{macro}{\prf} %\begin{macro}{\prp} %\begin{macro}{\prg} %\begin{macro}{\mac} %\begin{macro}{\puncture} %\begin{macro}{\source} %\begin{macro}{\predictor} %\begin{macro}{\sam} %\begin{macro}{\dist} %\begin{macro}{\distinguisher} %\begin{macro}{\simulator} %\begin{macro}{\ext} %\begin{macro}{\extractor} % The \emph{primitives} package option defines various cryptographic primitives. % \begin{macrocode} \DeclareOption{primitives}{ % \end{macrocode} % Zero knowledge % \begin{macrocode} \providecommand{\prover}{\pcalgostyle{P}} \providecommand{\verifier}{\pcalgostyle{V}} \providecommand{\nizk}{\pcalgostyle{NIZK}} % \end{macrocode} % Hash % \begin{macrocode} \providecommand{\hash}{\pcalgostyle{H}} \providecommand{\gash}{\pcalgostyle{G}} \providecommand{\fash}{\pcalgostyle{F}} \providecommand{\pad}{\pcalgostyle{pad}} % \end{macrocode} % Encryption % \begin{macrocode} \providecommand{\enc}{\pcalgostyle{Enc}} \providecommand{\dec}{\pcalgostyle{Dec}} % \end{macrocode} % Signatures % \begin{macrocode} \providecommand{\sig}{\pcalgostyle{Sig}} \providecommand{\sign}{\pcalgostyle{Sign}} \providecommand{\verify}{\pcalgostyle{Vf}} % \end{macrocode} % Obfuscation % \begin{macrocode} \providecommand{\obf}{\pcalgostyle{O}} \providecommand{\iO}{\pcalgostyle{iO}} \providecommand{\diO}{\pcalgostyle{diO}} % \end{macrocode} % One-wayness % \begin{macrocode} \providecommand{\owf}{\pcalgostyle{OWF}} \providecommand{\owp}{\pcalgostyle{OWP}} \providecommand{\tdf}{\pcalgostyle{TF}} \providecommand{\inv}{\pcalgostyle{Inv}} \providecommand{\hcf}{\pcalgostyle{HC}} % \end{macrocode} % Pseudorandomness % \begin{macrocode} \providecommand{\prf}{\pcalgostyle{PRF}} \providecommand{\prp}{\pcalgostyle{PRP}} \providecommand{\prg}{\pcalgostyle{PRG}} % \end{macrocode} % Message authentication code % \begin{macrocode} \providecommand{\mac}{\pcalgostyle{MAC}} % \end{macrocode} % Puncture % \begin{macrocode} \providecommand{\puncture}{\pcalgostyle{Puncture}} % \end{macrocode} % Misc % \begin{macrocode} \providecommand{\source}{\pcalgostyle{S}} \providecommand{\predictor}{\pcalgostyle{P}} \providecommand{\sam}{\pcalgostyle{Sam}} \providecommand{\dist}{\pcalgostyle{D}} \providecommand{\distinguisher}{\pcalgostyle{Dist}} \providecommand{\simulator}{\pcalgostyle{Sim}} \providecommand{\ext}{\pcalgostyle{Ext}} \providecommand{\extractor}{\ext} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{oracles} % %\begin{macro}{\Oracle} %\begin{macro}{\oracle} %\begin{macro}{\ro} % The \emph{oracles} package option defines macros for typesetting oracles. % \begin{macrocode} \DeclareOption{oracles}{ \providecommand{\Oracle}[1]{\pcalgostyle{O{#1}}} \def\oracle{\bgroup\oracle@} \newcommand{\oracle@}[1][]{\ifthenelse{\equal{#1}{}}{\oracle@@{O}}{\oracle@@{#1}}} \def\oracle@@#1{\pcoraclestyle{#1}\egroup} \providecommand{\ro}{\pcoraclestyle{RO}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % % % \subsubsection{events} % %\begin{macro}{\event} %\begin{macro}{\nevent} %\begin{macro}{\bad} %\begin{macro}{\nbad} % The \emph{events} package option defines macros for typesetting % events (probabilistic). % Also defines |\bad| as a \emph{bad event} often used in game based proofs. % \begin{macrocode} \DeclareOption{events}{ \providecommand{\event}[1]{\ensuremath{\mathsf{#1}}} \providecommand{\nevent}[1]{\ensuremath{\overline{\event{#1}}}} \providecommand{\bad}{\ensuremath{\event{bad}}} \providecommand{\nbad}{\ensuremath{\nevent{bad}}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % % \subsubsection{complexity} % %\begin{macro}{\complclass} %\begin{macro}{\cocomplclass} %\begin{macro}{\npol} %\begin{macro}{\conpol} %\begin{macro}{\pol} %\begin{macro}{\bpp} %\begin{macro}{\ppoly} %\begin{macro}{\AM} %\begin{macro}{\coAM} %\begin{macro}{\AC} %\begin{macro}{\NC} %\begin{macro}{\TC} %\begin{macro}{\PH} %\begin{macro}{\csigma} %\begin{macro}{\cpi} %\begin{macro}{\cosigma} %\begin{macro}{\copi} % The \emph{complexity} package option defines various complexity classes. % The style can be adjusted via |\pccomplexitystyle| % \begin{macrocode} \DeclareOption{complexity}{ \providecommand{\complclass}[1]{\pccomplexitystyle{#1}} \providecommand{\cocomplclass}[1]{\pccomplexitystyle{co}\pcmathhyphen{}\pccomplexitystyle{#1}} \providecommand{\npol}{\pccomplexitystyle{NP}} \providecommand{\conpol}{\cocomplclass{NP}} \providecommand{\pol}{\pccomplexitystyle{P}} \providecommand{\bpp}{\pccomplexitystyle{BPP}} \providecommand{\ppoly}{\ensuremath{\pol/\mathrm{poly}}} \providecommand{\AM}{\pccomplexitystyle{AM}} \providecommand{\coAM}{\cocomplclass{AM}} \providecommand{\AC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{AC}}{\pccomplexitystyle{AC}^{#1}}}} \providecommand{\NC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{NC}}{\pccomplexitystyle{NC}^{#1}}}} \providecommand{\TC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{TC}}{\pccomplexitystyle{TC}^{#1}}}} \providecommand{\PH}{\pccomplexitystyle{PH}} \providecommand{\csigma}[1]{\pccomplexitystyle{\Sigma}^p_{#1}} \providecommand{\cpi}[1]{\pccomplexitystyle{\Pi}^p_{#1}} \providecommand{\cosigma}[1]{\cocomplclass{\Sigma}^p_{#1}} \providecommand{\copi}[1]{\cocomplclass{\Pi}^p_{#1}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % % \subsubsection{asymptotics} % %\begin{macro}{\negl} %\begin{macro}{\poly} %\begin{macro}{\cc} %\begin{macro}{\ee} %\begin{macro}{\kk} %\begin{macro}{\mm} %\begin{macro}{\nn} %\begin{macro}{\pp} %\begin{macro}{\qq} %\begin{macro}{\rr} % The \emph{asymptotics} package option defines \enquote{polynomials} \cc\ (|\cc|), % \ee\ (|\ee|), \kk\, (|\kk|), \mm\ (|\mm|), \nn\ (|\nn|), \pp\ (|\pp|), and \qq\ (|\qq|) as well as macros |\negl| and |\poly|. % \begin{macrocode} \DeclareOption{asymptotics}{ \providecommand{\negl}[1][\secpar]{% \pcpolynomialstyle{negl}\ifthenelse{\equal{#1}{}}{}{\pc@olrk*{#1}}} \providecommand{\poly}[1][\secpar]{% \pcpolynomialstyle{poly}\ifthenelse{\equal{#1}{}}{}{\pc@olrk*{#1}}} \def\pp{\bgroup\pp@} \newcommand{\pp@}[1][]{\ifthenelse{\equal{#1}{}}{\pp@@{p}}{\pp@@{#1}}} \def\pp@@#1{\pcpolynomialstyle{#1}\egroup} \providecommand{\cc}{\pcpolynomialstyle{c}} \providecommand{\ee}{\pcpolynomialstyle{e}} \providecommand{\kk}{\pcpolynomialstyle{k}} \providecommand{\mm}{\pcpolynomialstyle{m}} \providecommand{\nn}{\pcpolynomialstyle{n}} \providecommand{\qq}{\pcpolynomialstyle{q}} \providecommand{\rr}{\pcpolynomialstyle{r}} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{keys} % %\begin{macro}{\pk} %\begin{macro}{\vk} %\begin{macro}{\sk} %\begin{macro}{\key} %\begin{macro}{\hk} %\begin{macro}{\gk} %\begin{macro}{\fk} %\begin{macro}{\st} %\begin{macro}{\state} % The \emph{keys} package option defines various \enquote{keys} such as % a symmetric and general purpose \key\ (|\key|) or an asymmetric key pair % \pk, \sk\ (|\pk| and |\sk|) % \begin{macrocode} \DeclareOption{keys}{ \providecommand{\pk}{\pckeystyle{pk}} \providecommand{\vk}{\pckeystyle{vk}} \providecommand{\sk}{\pckeystyle{sk}} \def\key{\bgroup\key@} \newcommand{\key@}[1][]{\ifthenelse{\equal{#1}{}}{\key@@{k}}{\key@@{#1}}} \def\key@@#1{\pckeystyle{#1}\egroup} \providecommand{\hk}{\pckeystyle{hk}} \providecommand{\gk}{\pckeystyle{gk}} \providecommand{\fk}{\pckeystyle{fk}} \providecommand{\st}{\pckeystyle{st}} \def\state{\bgroup\state@} \newcommand{\state@}[1][]{\ifthenelse{\equal{#1}{}}{\state@@{state}}{\state@@{#1}}} \def\state@@#1{\pckeystyle{#1}\egroup} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % \subsubsection{Security parameter} % % %\begin{macro}{\SECPAR} %\begin{macro}{\secpar} %\begin{macro}{\secparam} % The \emph{n} option defines security parameter macros |\secpar| and |\secparam| % using $n$. % See also \enquote{lambda} package option. % \begin{macrocode} \DeclareOption{n}{ \providecommand{\SECPAR}{\ensuremath{{N_0}}} \providecommand{\secpar}{\ensuremath{n}} \providecommand{\secparam}{\ensuremath{1^\secpar}} } % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % % %\begin{macro}{\SECPAR} %\begin{macro}{\secpar} %\begin{macro}{\secparam} % The \emph{n} option defines security parameter macros |\secpar| and |\secparam| % using $\lambda$. % See also \enquote{n} package option. % \begin{macrocode} \DeclareOption{lambda}{ \renewcommand{\SECPAR}{\ensuremath{\Lambda}} \renewcommand{\secpar}{\ensuremath{\lambda}} \renewcommand{\secparam}{\ensuremath{1^\secpar}} } % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % % \subsection{Preamble and Option Parsing} % % Print a warning in case an undefined package option is provided. % \begin{macrocode} \DeclareOption*{% \PackageError{cryptocode}{Unknown option ‘\CurrentOption’}% } % \end{macrocode} % % By default, only the \emph{n} option (security parameter as $n$ and $1^n$) is loaded % \begin{macrocode} \ExecuteOptions{n} % \end{macrocode} % % We are now ready to process all package options % \begin{macrocode} \ProcessOptions\relax % \end{macrocode} % % The cryptocode package depends on various external packages which are % loaded next. Note that the \emph{amsfonts} package is optional and can be % disabled via the \emph{noamsfonts} package option. % % Note that amsmath and mathtools have been loaded already earlier. % \begin{macrocode} \RequirePackage{etex} \if@pc@opt@amsfonts \RequirePackage{amsfonts} \fi \if@pc@opt@centernot \RequirePackage{centernot} \fi \RequirePackage{xcolor} \RequirePackage{calc} \RequirePackage{tikz} \usetikzlibrary{positioning,calc} \RequirePackage{ifthen} \RequirePackage{xargs} \RequirePackage{pgf} \RequirePackage{forloop} \RequirePackage{array} \RequirePackage{xparse} \RequirePackage{expl3} \RequirePackage{pbox} \RequirePackage{varwidth} \RequirePackage{suffix} \RequirePackage{etoolbox} \RequirePackage{environ} \RequirePackage{xkeyval} % \end{macrocode} % % % %\begin{macro}{\pcadvantagesuperstyle} %\begin{macro}{\pcadvantagename} %\begin{macro}{\pcadvantagesubstyle} %\begin{macro}{\advantage} % The \emph{advantage} option defines an |\advantage| command for typesetting % advantage declarations of adversaries. % \begin{macrocode} \if@pc@opt@advantage \providecommand{\pcadvantagesuperstyle}[1]{\mathrm{\MakeLowercase{#1}}} \providecommand{\pcadvantagesubstyle}[1]{#1} \providecommand{\pcadvantagename}{\mathsf{Adv}} \newcommandx*{\advantage}[3][3=(\secpar)]{\ensuremath{\pcadvantagename^{\pcadvantagesuperstyle{#1}}_{\pcadvantagesubstyle{#2}}#3}} \fi % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % \subsection{Global Macros} % % % % % \subsubsection{Styles} % % % %\begin{macro}{\pcalgostyle} %\begin{macro}{\pcsetstyle} %\begin{macro}{\pccomplexitystyle} %\begin{macro}{\pcpolynomialstyle} %\begin{macro}{\pcadvstyle} %\begin{macro}{\pcnotionstyle} %\begin{macro}{\pckeystyle} %\begin{macro}{\pcmachinemodelstyle} %\begin{macro}{\pcoraclestyle} % Definition of styles for algorithms, sets, complexity classes, polynomials, % adversaries, notions, keys, and machine models. % \begin{macrocode} \providecommand{\pcalgostyle}[1]{\ensuremath{\mathsf{#1}}} \providecommand{\pcsetstyle}[1]{\ensuremath{\mathbb{#1}}} \providecommand{\pccomplexitystyle}[1]{\ensuremath{\mathsf{#1}}} \providecommand{\pcpolynomialstyle}[1]{\ensuremath{\mathsf{#1}}} \providecommand{\pcadvstyle}[1]{\ensuremath{\mathcal{#1}}} \providecommand{\pcnotionstyle}[1]{\ensuremath{\mathrm{#1}}} \providecommand{\pckeystyle}[1]{\ensuremath{\mathsf{\protect\vphantom{p}#1}}} \providecommand{\pcmachinemodelstyle}[1]{\ensuremath{\mathsf{#1}}} \providecommand{\pcoraclestyle}[1]{\ensuremath{\mathsf{#1}}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{Order of Growth} % %\begin{macro}{\pc@olrk} %\begin{macro}{\pc@olrk*} %\begin{macro}{\pc@elrk} %\begin{macro}{\pc@elrk*} %\begin{macro}{\pc@clrk} %\begin{macro}{\pc@clrk*} % Define order of growth helper macros. These are optionally defined depending % on the loaded package options. % \begin{macrocode} \DeclarePairedDelimiter\pc@olrk{(}{)} \DeclarePairedDelimiter\pc@elrk{[}{]} \DeclarePairedDelimiter\pc@clrk{\{}{\}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{Spacing} % %\begin{macro}{\pcaboveskip} %\begin{macro}{\pcbelowskip} %\begin{macro}{\pcbeforeskip} %\begin{macro}{\pcafterskip} % Control the spacing before (resp.~after) pseudocode and stacking blocks both % vertically and horizontally. % \begin{macrocode} \newlength\pcaboveskip \setlength\pcaboveskip{\abovedisplayskip} \newlength\pcbelowskip \setlength\pcbelowskip{\belowdisplayskip} \newlength\pcbeforeskip \newlength\pcafterskip % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % % \subsubsection{Keywords and Highlighting} % % %\begin{macro}{\highlightkeyword} %\begin{macro}{\highlightaltkeyword} % Commands for highlighting primary and secondary keywords. % Both commands take an optional first parameter to control spacing % \begin{macrocode} \newcommand{\highlightkeyword}[2][\ ]{\ensuremath{\mathbf{#2}}#1} \newcommand{\highlightaltkeyword}[2][\ ]{\ensuremath{\mathsf{#2}}#1} % \end{macrocode} %\end{macro} %\end{macro} % % % %\begin{macro}{\pcglobvar} %\begin{macro}{\pcnew} %\begin{macro}{\pcwhile} %\begin{macro}{\pcendwhile} %\begin{macro}{\pcdo} %\begin{macro}{\pcif} %\begin{macro}{\pcunless} %\begin{macro}{\pcelse} %\begin{macro}{\pcelseif} %\begin{macro}{\pcfi} %\begin{macro}{\pcendif} %\begin{macro}{\pcendfor} %\begin{macro}{\pcthen} %\begin{macro}{\pcreturn} %\begin{macro}{\pcin} %\begin{macro}{\pcfor} %\begin{macro}{\pcrepeat} %\begin{macro}{\pcrepeatuntil} %\begin{macro}{\pcforeach} %\begin{macro}{\pcendforeach} %\begin{macro}{\pcuntil} %\begin{macro}{\pccontinue} %\begin{macro}{\pcfalse} %\begin{macro}{\pctrue} %\begin{macro}{\pcnull} %\begin{macro}{\pcdone} %\begin{macro}{\pcparse} %\begin{macro}{\pcfail} %\begin{macro}{\pcabort} % All predefined (highlightable) keywords. % \begin{macrocode} \newcommand{\pcglobvar}{\highlightkeyword{gbl}} \newcommand{\pcnew}{\highlightkeyword{new}} \newcommand{\pcwhile}{\@pc@increaseindent\highlightkeyword{while}} \newcommand{\pcendwhile}{\@pc@decreaseindent\highlightkeyword{endwhile}} \newcommandx*{\pcdo}[2][1=\ ,2=]{#1\highlightkeyword[#2]{do}} \newcommandx*{\pcif}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{if}} \newcommandx*{\pcunless}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{unless}} \newcommandx*{\pcelse}[1][1=\ ]{\@pc@tmpdecreaseindent\highlightkeyword[#1]{else}} \newcommandx*{\pcelseif}[1][1=\ ]{\@pc@tmpdecreaseindent\highlightkeyword[#1]{else if}} \newcommand{\pcfi}{\@pc@decreaseindent\highlightkeyword{fi}} \newcommand{\pcendif}{\@pc@decreaseindent\highlightkeyword{endif}} \newcommand{\pcendfor}{\@pc@decreaseindent\highlightkeyword{endfor}} \newcommandx*{\pcthen}[2][1=\ ,2=\ ]{#1\highlightkeyword[#2]{then}} \newcommand{\pcreturn}{\highlightkeyword{return}} \newcommandx*{\pcin}[2][1=\ ,2=]{#1\highlightkeyword[#2]{in}} \newcommandx*{\pcfor}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{for}} \newcommand{\pcrepeat}[1]{% \@pc@increaseindent\ensuremath{% \highlightkeyword{repeat} #1\ \highlightkeyword{times}% }} \newcommand{\pcrepeatuntil}[2]{% \ensuremath{\highlightkeyword{repeat}\ #1\ \highlightkeyword{until}\ #2}} \newcommand{\pcforeach}{\@pc@increaseindent\highlightkeyword{foreach}} \newcommand{\pcendforeach}{\@pc@decreaseindent\highlightkeyword{endforeach}} \newcommand{\pcuntil}{\@pc@decreaseindent\highlightkeyword{until}} \newcommand{\pccontinue}{\highlightkeyword{continue}} \newcommandx*{\pcfalse}[2][1=\ ,2=]{\highlightkeyword[#2]{false}} \newcommandx*{\pctrue}[2][1=\ ,2=]{\highlightkeyword[#2]{true}} \newcommandx*{\pcnull}[2][1=\ ,2=]{\highlightkeyword[#2]{null}} \newcommand{\pcdone}{\highlightkeyword{done}} \newcommand{\pcparse}{\highlightkeyword{parse}} \newcommand{\pcfail}{\highlightkeyword{fail}} \newcommand{\pcabort}{\highlightkeyword{abort}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % \subsubsection{Misc} % % %\begin{macro}{\pcmathhyphen} % Definition of a hyphen to be used within math formulas. % \begin{macrocode} \mathchardef\pcmathhyphen ="2D % \end{macrocode} %\end{macro} % % %\begin{macro}{\pccomment} %\begin{macro}{\pclinecomment} % Programming style line comment prefixing the comment with a double slash. % An optional first parameter allows to control the spacing before the comment % (defaults to 1em). % \begin{macrocode} \newcommand{\pccomment}[2][1em]{\hspace{#1}{\mbox{/\!\!/ } \text{\scriptsize#2}}} \newcommand{\pclinecomment}[2][0em]{\hspace{#1}{\mbox{/\!\!/ } \text{\scriptsize#2}}} % \end{macrocode} %\end{macro} %\end{macro} % % % \subsection{Internal Helper Functions} % % %\begin{macro}{\@expandedsetkeys} %^^A https://tex.stackexchange.com/questions/27172/how-can-i-detect-if-im-inside-or-outside-of-a-float-environment % \begin{macrocode} \newcommand\@pc@ifinfloat[2]{\ifnum\@floatpenalty<0\relax#1\else#2\fi} % \end{macrocode} %\end{macro} % %\begin{macro}{\@expandedsetkeys} % Calls |\setkeys| from the xkeyval package but before exapands argument number 4. % Arguments \marg{families} \marg{na} \marg{first set of keys} \marg{keys to be expanded} \marg{final set of keys} % \begin{macrocode} \newcommand*\@expandedsetkeys[5]{\expandafter\@expandedsetkeys@\expandafter{#4}{#1}{#2}{#3}{#5}} \def\@expandedsetkeys@#1#2#3#4#5{\setkeys{#2}[#3]{#4,#1,#5}} % \end{macrocode} %\end{macro} % % \begin{macrocode} \newenvironment{@pc@withspaces} {\obeyspaces\begingroup\lccode`~=` \lowercase{\endgroup\let~}\ } {} % \end{macrocode} % %\begin{macro}{\@pc@settowidthofalign} %\begin{macro}{\@pc@settowidthofaligned} % Commands to measure width of an align (resp. aligned) environment. Takes two arguments % a length in which to store the resulting width and the content. % \begin{macrocode} \newcommand{\@pc@settowidthofalign}[2]{% \setbox\z@=\vbox{\@pseudocodecodesize \begin{flalign*} #2 \ifmeasuring@\else\global\let\got@maxcolwd\maxcolumn@widths\fi \end{flalign*} }% \begingroup \def\or{+}\edef\x{\endgroup#1=\dimexpr\got@maxcolwd\relax}\x} \newcommand{\@pc@settowidthofaligned}[2]{% \settowidth{#1}{\@pseudocodesubcodesize$\begin{aligned}#2\end{aligned}$}} % \end{macrocode} %\end{macro} %\end{macro} % % % %\begin{macro}{\@pc@ifdraft} % Check for draft mode. % \begin{macrocode} \def\@pc@ifdraft{\ifdim\overfullrule>\z@ \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} % \end{macrocode} %\end{macro} % % %\begin{macro}{\@pc@executeblindly} % Run stuff in an empty box % \begin{macrocode} \newcommand{\@pc@executeblindly}[1]{% \setbox\z@=\vbox{#1 }} % \end{macrocode} %\end{macro} % % % We need to fiddle with the label command to use it in |\pseudocode|. To % access the original, we store it in % \begin{macrocode} \AtBeginDocument{ \let\@pc@original@label\ltx@label } % \end{macrocode} % % %\begin{macro}{\@pc@globaladdtolength} %\begin{macro}{\@pc@globalsetlength} % A helper command to set (resp.~add to) the length to a given value globally % even when being within a scoped grouping. % \begin{macrocode} \newcommand*{\@pc@globaladdtolength}[2]{% \addtolength{#1}{#2}% \global#1=#1\relax} \newcommand*{\@pc@globalsetlength}[2]{% \setlength{#1}{#2}% \global#1=#1\relax} % \end{macrocode} %\end{macro} %\end{macro} % % % % % %\begin{macro}{@pc@global@pc@cnt} %\begin{macro}{@pc@global@pc@nestcnt} % A global counter storing the number of times the pseudocode command was triggered. % \begin{macrocode} \newcounter{@pc@global@pc@cnt} \newcounter{@pc@global@pc@nestcnt} % \end{macrocode} %\end{macro} %\end{macro} % % % % % % Fix hyperref package.. gnarl http://tex.stackexchange.com/questions/130319/incompatibility-between-etoolbox-and-hyperref % \begin{macrocode} \providecommand{\pcfixhyperref}{ \global\let\textlabel\label \global\let\@pc@original@label\textlabel %\global\let\@pc@original@label\relax %\global\let\label\relax } % \end{macrocode} % % % % % % \subsection{Stacking} % % In the following we define two stacking environments |pchstack| and |pcvstack| % to layout multiple pseudocode blocks. % % % % \subsubsection{Manual Spacing} % % \begin{macrocode} % \newcommand{\pchspace}[1][1em]{\hspace{#1}} \newcommand{\pcvspace}[1][\baselineskip]{\par\vspace{#1}} % % \end{macrocode} % % % \subsubsection{Misc} % %\begin{macro}{@pc@stackdepth} %\begin{macro}{\@pc@incstackdepth} %\begin{macro}{\@pc@decstackdepth} % Counter to keep track of nesting level of stacks. % \begin{macrocode} \newcounter{@pc@stackdepth} \newcommand{\@pc@incstackdepth}{\addtocounter{@pc@stackdepth}{1}} \newcommand{\@pc@decstackdepth}{\addtocounter{@pc@stackdepth}{-1}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % \subsubsection{Stacking Options} % %\begin{macro}{center} %\begin{macro}{\@pc@centerstack} % Allows to center the stack. % \begin{macrocode} \newcommand{\@pc@centerstack}{false} \define@key{pcstack}{center}[true]{\ifthenelse{\equal{#1}{true}} {\renewcommand{\@pc@centerstack}{true}} {\renewcommand{\@pc@centerstack}{false}}}% % \end{macrocode} %\end{macro} %\end{macro} % % %\begin{macro}{boxed} %\begin{macro}{\@pc@boxedstack} % Allows to draw a box around the stack. % \begin{macrocode} \newcommand{\@pc@boxedstack}{false} \define@key{pcstack}{boxed}[true]{\ifthenelse{\equal{#1}{true}} {\renewcommand{\@pc@boxedstack}{true}} {\renewcommand{\@pc@boxedstack}{false}}}% % \end{macrocode} %\end{macro} %\end{macro} % % %\begin{macro}{noindent} %\begin{macro}{\@pc@noindentstack} % Allows to draw a box around the stack. % \begin{macrocode} \newcommand{\@pc@noindentstack}{false} \define@key{pcstack}{noindent}[true]{\ifthenelse{\equal{#1}{true}} {\renewcommand{\@pc@noindentstack}{true}} {\renewcommand{\@pc@noindentstack}{false}}}% % \end{macrocode} %\end{macro} %\end{macro} % % %\begin{macro}{inline} %\begin{macro}{\@pc@inlinestack} % Allows to keep the pchstack inline and not creating a paragraph. % \begin{macrocode} \newcommand{\@pc@inlinestack}{false} \define@key{pcstack}{inline}[true]{\ifthenelse{\equal{#1}{true}} {\renewcommand{\@pc@inlinestack}{true}} {\renewcommand{\@pc@inlinestack}{false}}}% % \end{macrocode} %\end{macro} %\end{macro} % % % %\begin{macro}{space} %\begin{macro}{\pchstackspace} %\begin{macro}{\pcvstackspace} %\begin{macro}{\@pc@centerstack} % Introduces horizontal (resp.~vertical) space in-between pseudocode blocks % in stacking environments . % \begin{macrocode} \providecommand{\pchstackspace}{0pt} \providecommand{\pcvstackspace}{0pt} \newcommand{\@pc@stackspace@forpseudocode}{} \newlength{\@pc@stackspace@len} \newcommand*{\@pc@stackspace}{0pt} \newcommand*{\@pc@reset@stackspace}{\setlength{\@pc@stackspace@len}{\@pc@stackspace}} \define@key{pcstack}{space}[0pt]{\renewcommand*{\@pc@stackspace}{#1}}% % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{aboveskip} %\begin{macro}{\@pc@applyaboveskipinstack} %\begin{macro}{\@pc@addabovespaceunlessstacking} % By default |\pcaboveskip| is applied on the outer most stacking environment. % Can be overriden using |aboveskip|. % \begin{macrocode} \newcommand{\@pc@addabovespaceunlessstacking}{% \ifthenelse{\value{@pc@stackdepth}=0}{\par\addvspace{\pcaboveskip}}{}} \newcommand{\@pc@applyaboveskipinstack}{\@pc@addabovespaceunlessstacking} \let\org@pc@applyaboveskipinstack\@pc@applyaboveskipinstack \define@key{pcstack}{aboveskip}[default]{\ifthenelse{\equal{#1}{default}} {\renewcommand{\@pc@applyaboveskipinstack}{\org@pc@applyaboveskipinstack}} {\renewcommand{\@pc@applyaboveskipinstack}{\vspace{#1}}}}% % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{belowskip} %\begin{macro}{\@pc@applybelowskipinstack} %\begin{macro}{\@pc@addbelowspaceunlessstacking} % By default |\pcbelowskip| is applied on the outer most stacking environment. % Can be overriden using |belowskip|. % \begin{macrocode} \newcommand{\@pc@addbelowspaceunlessstacking}{% \ifthenelse{\value{@pc@stackdepth}=0} {\@pc@ifinfloat{}{\par\addvspace{\pcbelowskip}}} {}} \newcommand{\@pc@applybelowskipinstack}{\@pc@addbelowspaceunlessstacking} \let\org@pc@applybelowskipinstack\@pc@addbelowspaceunlessstacking \define@key{pcstack}{belowskip}[default]{\ifthenelse{\equal{#1}{default}} {\renewcommand{\@pc@applybelowskipinstack}{\org@pc@applybelowskipinstack}} {\renewcommand{\@pc@applybelowskipinstack}{\par\addvspace{#1}}}}% % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{\pcbeforehstackskip} %\begin{macro}{\pcafterhstackskip} %Allows adding global skips before and after |\pchstack| blocks. % \begin{macrocode} \newlength{\pcbeforehstackskip} \newlength{\pcafterhstackskip} % \end{macrocode} %\end{macro} %\end{macro} % % % %\begin{macro}{\@pc@boxedstack} % For |\pchstack| and |\pcvstack| we use a box to store temporary results. % \begin{macrocode} \newsavebox{\@pc@stackcontentbox}% % \end{macrocode} %\end{macro} % % %\begin{macro}{\pcsethstackargs} %\begin{macro}{\pcsetvstackargs} % \begin{macrocode} \newcommand*\@pc@hstack@defaultargs{} \newcommand*\pcsethstackargs[1]{\renewcommand*\@pc@hstack@defaultargs{#1}} \newcommand*\@pc@vstack@defaultargs{} \newcommand*\pcsetvstackargs[1]{\renewcommand*\@pc@vstack@defaultargs{#1}} % \end{macrocode} %\end{macro} %\end{macro} % % \subsubsection{The Stacking Environments} % %\begin{macro}{pccenter} % \begin{macrocode} \newenvironment{pccenter}{% \setlength\topsep{0pt}\setlength\parskip{0pt}% \begin{center}}{\end{center}} % \end{macrocode} %\end{macro} % % %\begin{environment}{pchstack} % A stacking environment for horizontally stacked pseudocode blocks. % \begin{macrocode} \NewEnviron{pchstack}[1][]{% %Ensure that the parameters are defaulted \begingroup% % parse args this is the same as % \setkeys{pcstack}{center=false,boxed=false,aboveskip=default,belowskip=default,space=\pchstackspace,#1}% % expect that we expand the default args \@expandedsetkeys{pcstack}{}{center=false,boxed=false,aboveskip=default,belowskip=default,space=\pchstackspace}{\@pc@hstack@defaultargs}{#1}% \@pc@reset@stackspace% %add above skip except when in inline mode \ifthenelse{\equal{\@pc@inlinestack}{true}}{}{\@pc@applyaboveskipinstack}% \@pc@incstackdepth% \renewcommand{\@pc@stackspace@forpseudocode}{\hspace{\@pc@stackspace}}% %Store main content in a box \ifthenelse{\equal{\@pc@boxedstack}{true}}% {\sbox{\@pc@stackcontentbox} {\fbox{\mbox{\hspace{\pcbeforehstackskip}\BODY\hspace{\pcafterhstackskip}\hspace{-\@pc@stackspace}}}}}% {\sbox{\@pc@stackcontentbox} {\mbox{\hspace{\pcbeforehstackskip}\BODY\hspace{\pcafterhstackskip}\hspace{-\@pc@stackspace}}}}% % handle noindent \ifthenelse{\equal{\@pc@noindentstack}{true}}{\par\noindent\ignorespaces}{}% %set content either centered or directly \ifthenelse{\equal{\@pc@centerstack}{true}}% {\begin{pccenter}\usebox{\@pc@stackcontentbox}\end{pccenter}} {\usebox{\@pc@stackcontentbox}}% % cleanup \@pc@decstackdepth% \ifthenelse{\equal{\@pc@inlinestack}{true}}{}{\@pc@applybelowskipinstack}% \endgroup%reset space outside group \@pc@reset@stackspace% \@pc@stackspace@forpseudocode% %ignore any spaces after, to allow staying within paragraph \ignorespacesafterend\noindent% } % \end{macrocode} %\end{environment} % % %\begin{environment}{pchstack} % A stacking environment for vertically stacked pseudocode blocks. % \begin{macrocode} \NewEnviron{pcvstack}[1][]{% %Ensure that the parameters are defaulted \begingroup% % parse args this is the same as % \setkeys{pcstack}{center=false,boxed=false,aboveskip=default,belowskip=default,space=\pcvstackspace,#1} % expect that we expand the default args \@expandedsetkeys{pcstack}{}{center=false,boxed=false,aboveskip=default,belowskip=default,space=\pcvstackspace}{\@pc@vstack@defaultargs}{#1}% \@pc@reset@stackspace% \@pc@applyaboveskipinstack% \@pc@incstackdepth% \renewcommand{\@pc@stackspace@forpseudocode}{\par\vspace{\@pc@stackspace}}% %Store main content in a box \sbox{\@pc@stackcontentbox}{% \ifthenelse{\equal{\@pc@boxedstack}{true}}% {\fbox{\raisebox{\dimexpr\ht\strutbox-\height}{\begin{varwidth}[t]{2\linewidth}\BODY\end{varwidth}}}}% {\raisebox{\dimexpr\ht\strutbox-\height}{\begin{varwidth}[t]{2\linewidth}\BODY\end{varwidth}}}% \vspace{-\@pc@stackspace}}% % handle noindent \ifthenelse{\equal{\@pc@noindentstack}{true}}{\par\noindent\ignorespaces}{}% % display content \ifthenelse{\equal{\@pc@centerstack}{true}}% {\begin{pccenter}\usebox{\@pc@stackcontentbox}\end{pccenter}}% {\usebox{\@pc@stackcontentbox}}% % cleanup \@pc@decstackdepth% \@pc@applybelowskipinstack% \endgroup%reset space outside group \@pc@reset@stackspace% \@pc@stackspace@forpseudocode% %ignore any spaces after, to allow staying within paragraph \ignorespacesafterend\noindent% } % \end{macrocode} %\end{environment} % % % % \subsection{The pseudocode command} % % % % Define internal lengths used for measurements within pseudocode. % \begin{macrocode} \newlength{\@pc@minipage@length} \newlength{\@pc@alt@minipage@length} \newlength{\@pc@length@tmp@width@vstack} % \end{macrocode} % % % Define flags used in game based proofs. % \begin{macrocode} \newcommand{\@withingame}{false} \newcommand{\@withinbxgame}{false} \newcommand{\@withingamedescription}{false} % \end{macrocode} % % %\begin{macro}{\@bxgameheader} % Define a placeholder command which will take the current game header. % \begin{macrocode} \newcommand{\@bxgameheader}{} % \end{macrocode} %\end{macro} % % %\begin{macro}{\@pc@beginnewline} % An internal helper that is called at the beginning of each new line. % \begin{macrocode} \newlength\@pseudocodecodeminlineheight@len \newcommand{\@pc@beginnewline}{% \@pseudocodecodeatbeginline\@pseudocodelinenumber\@pc@and\@pcln@stephiddenlncnt% \setlength{\@pseudocodecodeminlineheight@len}{\@pseudocodecodeminlineheight}% \vphantom{\rule[0.5ex-0.5\@pseudocodecodeminlineheight@len]{0pt}{\@pseudocodecodeminlineheight@len}}% %checkspace \ifthenelse{\equal{\@pseudocodespace}{auto}}% {\expandafter\pcind\expandafter[\value{@pc@indentationlevel}]}% {}% %reset column counter \setcounter{pccolumncounter}{2}% %beginmode \@pc@modebegin} % \end{macrocode} %\end{macro} % % % %\begin{macro}{\@pc@and@wrap@end} %\begin{macro}{\@pc@and@wrap@start} % Every pseudocode line is wrapped in between |\@pc@and@wrap@start| and % |\@pc@and@wrap@end|. % \begin{macrocode} \newcommand{\@pc@and@wrap@start}{\@pc@beginnewline} \newcommand{\@pc@and@wrap@end}{\@pc@modeend&\@pseudocodecodeatendline} % \end{macrocode} %\end{macro} %\end{macro} % % %\begin{macro}{\@pc@and} % An internal helper to store the ampersand. As this is a special character % this is the easiest in order to place custom alignment tags. % \begin{macrocode} \newcommand{\@pc@and}{&} % \end{macrocode} %\end{macro} % % % %\begin{macro}{\pcind} % An indentation macro to be used within pseudocode. % As writing |\pcind| is a bit cumbersome, there is a shorthand that can % be defined via |\pcindentname| (defaults to t). See below. % \begin{macrocode} \newlength{\@pcindentwidth} \providecommand{\pcind}[1][1]{% \setlength{\@pcindentwidth}{\widthof{\ensuremath{\quad}}*#1}% \ensuremath{\mathmakebox[\@pcindentwidth]{}}} % \end{macrocode} %\end{macro} % % % %\begin{macro}{\pctabname} %\begin{macro}{\pcdbltabname} %\begin{macro}{\pcindentname} % Shorthands for alignment tabs and indentation. These are defined only within % the pseudocode scope. % \begin{macrocode} \newcommand{\pctabname}{>} \newcommand{\pcdbltabname}{<} \newcommand{\pcindentname}{t} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % % % % The following commands handle line numbering within the pseudocode command. The % pseudocode command itself does need to do some counter magic. We start % with a definition of various helper counters. % The H version of counters is needed to make hyperref happy % \begin{macrocode} \newcounter{pclinenumber} \newcounter{Hpclinenumber} \newcounter{@pclinenumber} \newcounter{H@pclinenumber} \newcounter{@pclinenumbertmp} \newcounter{pcgamecounter} \newcounter{Hpcgamecounter} \newcounter{pcrlinenumber} \newcounter{Hpcrlinenumber} \newcounter{@pcrlinenumbertmp} % \end{macrocode} % % The following implements some counter magic. When using automatic linenumbering % line numbers are nicely aligned before the first alignment tag. This, however % confuses hyperref and we thus have a second counter that is updated after the % first tag. This is done with the |\@pcln@stephiddenlncnt| % \begin{macrocode} \renewcommand{\the@pclinenumber}{\thepclinenumber} \providecommand{\@pcln@stephiddenlncnt}{% \refstepcounter{@pclinenumber}% \stepcounter{H@pclinenumber}% } % \end{macrocode} % % %\begin{macro}{\pclnseparator} %\begin{macro}{\pcrlnseparator} % Define separators between line numbers and code (left and right). % Note that line numbers can be displayed either to the left or to the right % of code. % \begin{macrocode} \providecommand{\pclnseparator}{:} \providecommand{\pcrlnseparator}{} % \end{macrocode} %\end{macro} %\end{macro} % % %\begin{macro}{\pclnspace} %\begin{macro}{\pclnrspace} % Define spacing between line numbers and code (left and right). % \begin{macrocode} \providecommand{\pclnspace}{1em} \providecommand{\pclnrspace}{0.5em} % \end{macrocode} %\end{macro} %\end{macro} % % %\begin{macro}{\pclnstyle} % \begin{macrocode} \providecommand\pclnstyle[1]{\text{\scriptsize#1}} % \end{macrocode} %\end{macro} % %\begin{macro}{pcln} % Manually place (left aligned) line numbers. % This command is also used by the automatic placement of line numbers. % \begin{macrocode} \providecommand{\pcln}{% \ifthenelse{\equal{\@pc@skiplnmarker}{1}}{\ifmeasuring@\else\@pc@resetskipln{}\fi}{% \refstepcounter{pclinenumber}% \stepcounter{Hpclinenumber}% \ifthenelse{\value{pclinenumber}<10}{\hspace{1ex}}{}% \pclnstyle{\arabic{pclinenumber}}\pclnseparator\hspace{\pclnspace}% }}% % \end{macrocode} %\end{macro} % % %\begin{macro}{\pcskipln} %\begin{macro}{\@pc@skiplnmarker} %\begin{macro}{skipfirstln} % allow to skip numbering single lines if linenumbering=on % \begin{macrocode} \def\@pc@skiplnmarker{} \providecommand{\pcskipln}{\ifmeasuring@\else\global\def\@pc@skiplnmarker{1}\fi} \newcommand{\@pc@resetskipln}{\global\def\@pc@skiplnmarker{}} \define@key{pseudocode}{skipfirstln}[1]{\global\def\@pc@skiplnmarker{1}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{\pclnr} %\begin{macro}{\pcrln} % Manual placement of right aligned line numbers using the same counter % (|\pclnr|) or a separate counter (|\pcrln|). % \begin{macrocode} \providecommand{\pclnr}{% \refstepcounter{pclinenumber}% \stepcounter{Hpclinenumber}% \hspace{\pclnrspace}\pcrlnseparator\pclnstyle{\arabic{pclinenumber}}} \providecommand{\pcrln}{ \refstepcounter{pcrlinenumber}% \stepcounter{Hpcrlinenumber}% \hspace{\pclnrspace}\pcrlnseparator\pclnstyle{\arabic{pcrlinenumber}}} % \end{macrocode} %\end{macro} %\end{macro} % % % \subsubsection{Options} % % % The following commands define a bunch of placeholders (plus their default values) % that are defined via the various options of the pseudocode command. % \begin{macrocode} \newcommand*\@pseudocodehead{} \newcommand*\@pseudocodewidth{} \newcommand*\@pseudocodexshift{0pt} \newcommand*\@pseudocodeyshift{0pt} \newcommand*\@pseudocodelinenumber{} \newcommand*\@pseudocodebeforeskip{0ex} \newcommand*\@pseudocodeafterskip{0ex} \newcommand*\@pseudocodelnstart{0} \newcommand*\@pseudocodelnstartright{0} \newcommand*\@pseudocodesyntaxhighlighting{} \newcommand*\@pseudocodenodraft{false} \newcommand*\@pseudocodecolspace{} % empty per default, use length, \newcommand*\@pseudocodeheadlinecmd{\hrule} % \end{macrocode} %\begin{macro}{headlinesep} %\begin{macro}{\pcheadlinesep} %\begin{macro}{\@pseudocodeheadlinesep} % Distance between header and line. % \begin{macrocode} \newlength\pcheadlinesep \setlength\pcheadlinesep{0pt} \newcommand*\@pseudocodeheadlinesep{0em} \define@key{pseudocode}{headlinesep}[0em]{\renewcommand*\@pseudocodeheadlinesep{#1}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{bodylinesep} %\begin{macro}{\pcbodylinesep} %\begin{macro}{\@pseudocodebodylinesep} % \begin{macrocode} \newlength\pcbodylinesep \setlength\pcbodylinesep{0.3\baselineskip} \newcommand*\@pseudocodebodylinesep{0em} \define@key{pseudocode}{bodylinesep}[0em]{\renewcommand*\@pseudocodebodylinesep{#1}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % %\begin{macro}{headheight} %\begin{macro}{\pcheadheight} %\begin{macro}{\@pc@headheightskip} %\begin{macro}{\@pseudocodeheadheight} % \begin{macrocode} \newlength\@pseudocodeheadheight@len \newcommand{\@pc@headheightskip}{% \setlength{\@pseudocodeheadheight@len}{\@pseudocodeheadheight}% \vphantom{\rule[0.5ex-0.5\@pseudocodeheadheight@len]{0pt}{\@pseudocodeheadheight@len}}% } \newlength\pcheadheight \setlength{\pcheadheight}{3.25ex} \newcommand*\@pseudocodeheadheight{\pcheadheight} \define@key{pseudocode}{headheight}[0em]{\renewcommand*\@pseudocodeheadheight{#1}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \begin{macrocode} \newcommand*\@pseudocodecolsep{0em} \newcommand*\@pseudocodeaddtolength{2pt} \newcommand*\@pseudocodecodeatbeginline{} \newcommand*\@pseudocodecodeatendline{} \newcommand*\@pseudocodecodejot{0em} \newcommand*\@pseudocodecodesize{\small} \newcommand*\@pseudocodesubcodesize{\footnotesize} \newcommand*\@pseudocodeminipagealign{t} % % Define keywords for the automatic syntax highlighting % the accompanying add provides additional keywords. % The space version for automatic spacing \newcommand*\@pseudocodekeywordsindent{for ,foreach ,if ,repeat ,while } \newcommand*\@pseudocodekeywordsunindent{endfor,endforeach,fi,endif,until,endwhile} \newcommand*\@pseudocodekeywordsuninindent{else if ,elseif ,else } \newcommand*\@pseudocodekeywords{for,foreach,{return },return,{ do },{ in },new,if, null, true,{until },{ to }, false,{ then},repeat,else if,elseif,while,else,done} \newcommand*\@pseudocodeaddkeywords{} \newcommand*\@pseudocodealtkeywords{} \begin{@pc@withspaces} \global\def\@pseudocodekeywordsspace{for,endfor,foreach,endforeach,return,do,in,new,if,null,true,until,to,false,then,repeat,else if,elseif,while,endwhile,else,done,fi,endif} \end{@pc@withspaces} % \end{macrocode} % % % Specification of the various options of the |\pseudocode| command. % \begin{macrocode} \define@key{pseudocode}{beginline}[]{\renewcommand*\@pseudocodecodeatbeginline{#1}} \define@key{pseudocode}{endline}[]{\renewcommand*\@pseudocodecodeatendline{#1}} \define@key{pseudocode}{jot}[0em]{\renewcommand*\@pseudocodecodejot{#1}} \define@key{pseudocode}{codesize}[\small]{\renewcommand*\@pseudocodecodesize{#1}} \define@key{pseudocode}{subcodesize}[\small]{\renewcommand*\@pseudocodesubcodesize{#1}} \define@key{pseudocode}{head}[]{\renewcommand*\@pseudocodehead{#1}} \define@key{pseudocode}{width}[]{\renewcommand*\@pseudocodewidth{#1}} \define@key{pseudocode}{valign}[t]{\renewcommand*\@pseudocodeminipagealign{#1}} \define@key{pseudocode}{xshift}[]{\renewcommand*\@pseudocodexshift{#1}} \define@key{pseudocode}{yshift}[]{\renewcommand*\@pseudocodeyshift{#1}} \define@key{pseudocode}{colspace}[]{\renewcommand*\@pseudocodecolspace{#1}} \define@key{pseudocode}{linenumbering}[on]{\ifthenelse{\equal{#1}{on}}{\renewcommand*\@pseudocodelinenumber{\pcln}}{\renewcommand*\@pseudocodelinenumber{}}} \define@key{pseudocode}{beforeskip}[]{\renewcommand*\@pseudocodebeforeskip{#1}} \define@key{pseudocode}{afterskip}[]{\renewcommand*\@pseudocodeafterskip{#1}} \define@key{pseudocode}{lnstart}[0]{\renewcommand*\@pseudocodelnstart{#1}} \define@key{pseudocode}{lnstartright}[0]{\renewcommand*\@pseudocodelnstartright{#1}} \define@key{pseudocode}{colsep}[0em]{\renewcommand*\@pseudocodecolsep{#1}} \define@key{pseudocode}{headlinecmd}[\hrule]{\renewcommand*\@pseudocodeheadlinecmd{#1}} \define@key{pseudocode}{addtolength}[2pt]{\renewcommand*\@pseudocodeaddtolength{#1}} \define@key{pseudocode}{nodraft}[true]{\renewcommand*\@pseudocodenodraft{#1}} \define@key{pseudocode}{keywords}[]{\renewcommand*\@pseudocodekeywords{#1}} \define@key{pseudocode}{keywordsindent}[]{\renewcommand*\@pseudocodekeywordsindent{#1}} \define@key{pseudocode}{keywordsunindent}[]{\renewcommand*\@pseudocodekeywordsunindent{#1}} \define@key{pseudocode}{keywordsuninindent}[]{\renewcommand*\@pseudocodekeywordsuninindent{#1}} \define@key{pseudocode}{addkeywords}[]{\renewcommand*\@pseudocodeaddkeywords{#1}} \define@key{pseudocode}{altkeywords}[]{\renewcommand*\@pseudocodealtkeywords{#1}} \define@key{pseudocode}{syntaxhighlight}[]{\renewcommand*\@pseudocodesyntaxhighlighting{#1}} % \end{macrocode} % % % %\begin{macro}{mode} % The \oarg{mode} key (with values \meta{text} or \meta{math} (default)) specifies % whether within a pseudocode block input is by default typeset in text mode or in % math mode. % The |\@pc...| variables are variables that help typesetting each line in a pseudocode block. % \begin{macrocode} \newcommand{\@pc@modebegin}{} \newcommand{\@pc@modeend}{} \define@key{pseudocode}{mode}[math]{% \ifthenelse{\equal{#1}{text}}{% \renewcommand*\@pc@modebegin{\begin{varwidth}{\textwidth}% %introduce line magic for text mode \let\@pc@lb\\% \renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and \@pseudocodecodeatendline\ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}% \def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}% \def\pcolb{\let\\\@pc@lb\relax\@pc@modeend\\}% }% \renewcommand*\@pc@modeend{\end{varwidth}}% }{\renewcommand{\@pc@modebegin}{}\renewcommand{\@pc@modeend}{}}} % \end{macrocode} %\end{macro} % % %\begin{macro}{minlineheight} %\begin{macro}{\pcminlineheight} %\begin{macro}{\@pseudocodecodeminlineheight} % Control the minimal line height of pseudocode blocks. % \begin{macrocode} \providecommand{\pcminlineheight}{0pt} \newcommand*\@pseudocodecodeminlineheight{\pcminlineheight} \define@key{pseudocode}{minlineheight}[0pt]{\renewcommand*\@pseudocodecodeminlineheight{#1}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % % % % \subsubsection{Automatic Syntax Highlighting and Spacing (Experimental)} % % % % % Experimental LaTex3 string substitution helpers for automatic keyword % highlighting. The regex parsing is (regrettably) super slow. % \begin{macrocode} \ExplSyntaxOn \tl_new:N \l_pc_strsub_input_tl \tl_new:N \l_pc_strsub_search_tl \tl_new:N \l_pc_strsub_replace_tl \NewDocumentCommand{\@pc@stringsubstitution}{mmm} { \tl_set:Nn \l_pc_strsub_input_tl { #1 } \tl_set:Nn \l_pc_strsub_search_tl { #2 } \tl_set:Nn \l_pc_strsub_replace_tl { #3 } % \tl_show_analysis:N \l_pc_strsub_input_tl % uncomment for debugging % \tl_show_analysis:N \l_pc_strsub_search_tl % uncomment for debugging % \tl_show_analysis:N \l_pc_strsub_replace_tl % uncomment for debugging \regex_replace_all:nnN { \u{l_pc_strsub_search_tl} } %only match if keyword does not have a word character preceding { \u{l_pc_strsub_replace_tl} } \l_pc_strsub_input_tl % \tl_show_analysis:N \l_tmpa_tl % uncomment for debugging \tl_use:N \l_pc_strsub_input_tl } \ExplSyntaxOff % \end{macrocode} % % % %\begin{macro}{\@pc@syntaxhighlight} %\begin{macro}{\@pc@highlight} %\begin{macro}{\@pc@highlightindent} %\begin{macro}{\@pc@highlightunindent} %\begin{macro}{\@pc@highlightuninindent} %\begin{macro}{\@pc@althighlight} % This is the core of the (experimental) automatic syntax highlighting and % automatic spacing. The code is ugly, and very slow. % It is not really recommended to be used in larger projects. % \begin{macrocode} \newcommand{\@pc@syntaxhighlight}[1]{% %don't highlight during measuring runs for performance improvements. \ifmeasuring@#1\else% \ifthenelse{\equal{\@pseudocodesyntaxhighlighting}{auto}}{% \def\@shtmp{#1}% first step % Depending on space mode, we might later run the indent/unindent/... lists % if not, we add them now to tmp lists in order to have a complete list. \ifthenelse{\equal{\@pseudocodespace}{keep}} {\edef\@tmpkeywords{\@pseudocodekeywordsspace,\@pseudocodeaddkeywords}} {\ifthenelse{\equal{\@pseudocodespace}{auto}} {\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodeaddkeywords}} {\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodekeywordsindent,\@pseudocodekeywordsunindent,\@pseudocodekeywordsuninindent,\@pseudocodeaddkeywords}}} \foreach \@pckw in \@tmpkeywords{% \ifthenelse{\equal{\@pckw}{}}{}{% % we are doing a simple strsub and storing the result (globally) in @shtmp \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlight\expandafter{\@pckw}}}% }}% alt keywords \foreach \@pckw in \@pseudocodealtkeywords{% \ifthenelse{\equal{\@pckw}{}}{}{% % we are doing a simple strsub and storing the result (globally) in @shtmp \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@althighlight\expandafter{\@pckw}}}% }}% % if automatic spacing \ifthenelse{\equal{\@pseudocodespace}{auto}} {% \foreach \@pckw in \@pseudocodekeywordsindent{% indentation keywords \ifthenelse{\equal{\@pckw}{}}{}{% % we are doing a simple strsub and storing the result (globally) in @shtmp \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightindent\expandafter{\@pckw}}}% }}% \foreach \@pckw in \@pseudocodekeywordsunindent{% unindentation keywords \ifthenelse{\equal{\@pckw}{}}{}{% % we are doing a simple strsub and storing the result (globally) in @shtmp \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightunindent\expandafter{\@pckw}}}% }}% \foreach \@pckw in \@pseudocodekeywordsuninindent{% uninindentation keywords \ifthenelse{\equal{\@pckw}{}}{}{% % we are doing a simple strsub and storing the result (globally) in @shtmp \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightuninindent\expandafter{\@pckw}}}% }}% }{}% % return result \@shtmp% }{#1}% nothing to highlight \fi} \newcommand{\@pc@highlight}[1]{% \ifthenelse{\equal{\@pseudocodespace}{keep}} {\highlightkeyword[]{#1}}% {\highlightkeyword[]{\@pc@stringsubstitution{#1}{ }{~}}}% } \newcommand{\@pc@highlightindent}[1]{% \@pc@increaseindent\@pc@highlight{#1}% } \newcommand{\@pc@highlightunindent}[1]{% \@pc@decreaseindent\@pc@highlight{#1}% } \newcommand{\@pc@highlightuninindent}[1]{% \@pc@tmpdecreaseindent\@pc@highlight{#1}% } \newcommand{\@pc@althighlight}[1]{% \ifthenelse{\equal{\@pseudocodespace}{keep}} {\highlightaltkeyword{#1}}% {\highlightaltkeyword{\@pc@stringsubstitution{#1}{ }{~}}}% } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \subsubsection{Helper Variables} % %\begin{macro}{\@pc@thecontent} %\begin{macro}{\@pc@colspace} % Helper variables used within pseudocode % \begin{macrocode} \newcommand{\@pc@thecontent}{} \newcommand{\@pc@colspace}{} % \end{macrocode} %\end{macro} %\end{macro} % % % % %\begin{macro}{\@withinspaces} %\begin{macro}{\@keepspaces} % Helper variables for controlling automatic spacing % \begin{macrocode} \newcommand{\@withinspaces}{false}% \newcommand{\@keepspaces}{% \renewcommand{\@withinspaces}{true}\@pc@withspaces% } % \end{macrocode} %\end{macro} %\end{macro} % % % \begin{macrocode} \newcommand*\@pseudocodespace{} \define@key{pcspace}{space}[]{\ifthenelse{\equal{#1}{keep}}{\@keepspaces}{}\renewcommand*\@pseudocodespace{#1}} \newcommand*\@pc@defaultargs{} \newcommand*\pcsetargs[1]{\renewcommand*\@pc@defaultargs{#1}} % automatic indentation \newcounter{@pc@indentationlevel} \newcommand{\@pc@increaseindent}{\addtocounter{@pc@indentationlevel}{1}} \newcommand{\@pc@decreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}\addtocounter{@pc@indentationlevel}{-1}} \newcommand{\@pc@tmpdecreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}} \newcounter{pccolumncounter} \setcounter{pccolumncounter}{2} % store original halign \let\@pc@halign\halign% % \end{macrocode} % % \subsubsection{The Actual Pseudocode Command} % % \begin{macrocode} % Check if the pseudocode command is called with an optional argument \providecommand{\pseudocode}{% \begingroup% \renewcommand{\@withinspaces}{false}% \@ifnextchar[%] {\@pseudocodeA}% {\@pseudocode[]}% } \def\@pseudocodeA[#1]{% \setkeys*{pcspace}{#1}%test if there is a space assignment within the keys .. make the necessary arrangements and call the actual method \@pseudocode[#1]% } \def\@pseudocode[#1]#2{% \begingroup% % reset skip marker before parsing options, as this might set it \@pc@resetskipln% % parse options % this is the same as %\setkeys{pseudocode}[space]{\@pc@defaultargs,#1}%ignore the space key. % expect that we expand the default args \@expandedsetkeys{pseudocode}{space}{head=}{\@pc@defaultargs}{#1}% % check draft mode and disable syntax highlighting \@pc@ifdraft{\ifthenelse{\equal{\@pseudocodenodraft}{true}}{}{\renewcommand\@pseudocodesyntaxhighlighting{}}}{}% % % \addtocounter{@pc@global@pc@nestcnt}{1}% % allow for tikz usage \@pc@ensureremember% % % create tabbing command \ifcsname \pctabname\endcsname% \expandafter\renewcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@colspace\@pc@modebegin}% \else% \expandafter\newcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@colspace\@pc@modebegin}% \fi% \ifcsname \pcdbltabname\endcsname% \expandafter\renewcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@colspace\@pc@modebegin}% \else% \expandafter\newcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@colspace\@pc@modebegin}% \fi% % create colspace command if necessary (must be empty for multicolumns \ifthenelse{\equal{\@pseudocodecolspace}{}} {} {\renewcommand{\@pc@colspace}{\hspace{\@pseudocodecolspace}}}% % %adjust row width \addtolength{\jot}{\@pseudocodecodejot}% % create indent command \expandafter\let\csname \pcindentname\endcsname\pcind% % %store and wrap (do syntax highlighting) argument \renewcommand{\@pc@thecontent}{\@pc@and@wrap@start\@pc@syntaxhighlight{#2}\@pc@and@wrap@end}% % %take care of counters \stepcounter{@pc@global@pc@cnt}% \setcounter{pclinenumber}{\@pseudocodelnstart}% \setcounter{pcrlinenumber}{\@pseudocodelnstartright}% \setlength{\@pc@minipage@length}{0pt}% \setlength{\@pc@alt@minipage@length}{0pt}% \setcounter{@pclinenumbertmp}{\value{pclinenumber}}% \setcounter{@pcrlinenumbertmp}{\value{pcrlinenumber}}% %reset column counter \setcounter{pccolumncounter}{2}% % % vertical space \vspace{\@pseudocodeyshift}% % % % % line magic \ifthenelse{\value{@pc@global@pc@nestcnt}=1}{% \let\@pc@halign\halign% \newenvironment{pcmbox}{\let\halign\@pc@halign}{}% \def\halign{% \renewcommand{\label}[1]{\ifmeasuring@\else\@pc@original@label{####1}\fi}% \let\@pc@lb\\% \renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and\@pseudocodecodeatendline \ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}% \def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}% \@pc@halign}% }{}% % %align column separation \renewcommand*{\minalignsep}{\@pseudocodecolsep}% % %as the following block will execute the pseudocode we need to store the skip command \edef\@pc@org@skiplnmarker{\@pc@skiplnmarker}% % if no width is set compute width and store in circuitlength \ifthenelse{\equal{\@pseudocodewidth}{}}{% % compute length of pseudocode \ifthenelse{\value{@pcsubprogstep}=0}{% \@pc@settowidthofalign{\@pc@minipage@length}{\@pc@thecontent}% }{% \@pc@settowidthofaligned{\@pc@minipage@length}{\@pc@thecontent}% }% %compute length of header \ifthenelse{\equal{\@withingame}{true}}% {\ifthenelse{\equal{\@pc@secondheader}{true}}% {\addtolength{\@pc@alt@minipage@length}{\widthof{x\ensuremath{\@pc@gametitle[1]\@pc@gametitle[1]}}}} {\addtolength{\@pc@alt@minipage@length}{\widthof{\ensuremath{\@pc@gametitle[1]}}}}}% {\addtolength{\@pc@alt@minipage@length}{\widthof{\@pseudocodehead}}}% % use header length if longer and add some points for good measure \ifdim\@pc@alt@minipage@length>\@pc@minipage@length% \setlength{\@pc@minipage@length}{\@pc@alt@minipage@length}% \fi% \addtolength{\@pc@minipage@length}{\@pseudocodeaddtolength}% }{\addtolength{\@pc@minipage@length}{\@pseudocodewidth}}% % reset counter and skip command \setcounter{pclinenumber}{\value{@pclinenumbertmp}}% \setcounter{pcrlinenumber}{\value{@pcrlinenumbertmp}}% \setcounter{@pc@indentationlevel}{0}% \edef\@pc@skiplnmarker{\@pc@org@skiplnmarker}% % begin actual output % % %do the actual mini page \hspace{\pcbeforeskip}\hspace{\@pseudocodexshift}% \ifthenelse{\equal{\@pseudocodeminipagealign}{t}}{% \raisebox{\dimexpr\ht\strutbox-\height}{\@pc@pseudocodeminipage{t}}% }{% \@pc@pseudocodeminipage{\@pseudocodeminipagealign}% }% \hspace{\pcafterskip}% % tikz usage \@pc@releaseremember% \addtocounter{@pc@global@pc@nestcnt}{-1}% \endgroup% % close spacing and potentially a single group generated by the space tester \ifthenelse{\equal{\@withinspaces}{true}}{\end@pc@withspaces}{}% \endgroup% %insert space from stacking \@pc@stackspace@forpseudocode% } \newcommand{\@pc@pseudocodeminipage}[1]{% \begin{minipage}[#1]{\@pc@minipage@length}% \ifthenelse{\value{@pcsubprogstep}=0}{% \pc@display@pseudocode{\@pseudocodehead}{\@pc@thecontent}% }{% if sub procedure \pc@display@subcode{\@pseudocodehead}{\@pc@thecontent}% }% \end{minipage}% } \newcommand{\@pc@display@gameheader}[1]{% \tikz{\gdef\i{\thepcgamecounter}% \node[anchor=base,text depth=0pt, inner sep=0.05em,outer sep=0pt] (gamenode\i) {#1}; \ifthenelse{\equal{\@withinbxgame}{true}} {\node[draw,anchor=base, above=2ex of gamenode\i] (bgamenode\i) {\@bxgameheader};} {}% }% } \let\pclb\relax % \newcommand{\pc@display@pseudocode}[2]{% \ifthenelse{\equal{#1}{}}{\vspace{-\baselineskip}\@pseudocodecodesize{}}{% \ifthenelse{\equal{\@withingame}{true}} {\ifthenelse{\equal{\@pc@secondheader}{true}} {\@pc@display@gameheader{#1}\addtocounter{pcgamecounter}{1}\fboxsep=1pt\fbox{\vphantom{#1}\@pc@display@gameheader{#1}}} {\@pc@display@gameheader{#1}}} {#1}% \@pc@headheightskip\vspace{\pcheadlinesep}\vspace{\@pseudocodeheadlinesep}\@pseudocodeheadlinecmd% \vspace{-\baselineskip}\vspace{\pcbodylinesep}\vspace{\@pseudocodebodylinesep}\@pseudocodecodesize}% \begin{flalign*}#2\end{flalign*}% } \newcommand{\pc@display@subcode}[2]{% \begingroup% \ifthenelse{\equal{#1}{}}{}{#1\@pc@headheightskip% \vspace{\pcheadlinesep}\vspace{\@pseudocodeheadlinesep}\@pseudocodeheadlinecmd{}% \vspace{\pcbodylinesep}\vspace{\@pseudocodebodylinesep}}% \@pseudocodesubcodesize% $\begin{aligned}#2\end{aligned}$% \endgroup% } \newcommand{\@pc@gettikzwidth}[2]{ % #1 = width, #2 = height \pgfextractx{\@tempdima}{\pgfpointdiff{\pgfpointanchor{current bounding box}{south west}} {\pgfpointanchor{current bounding box}{north east}}} \global#1=\@tempdima \pgfextracty{\@tempdima}{\pgfpointdiff{\pgfpointanchor{current bounding box}{south west}} {\pgfpointanchor{current bounding box}{north east}}} \global#2=\@tempdima } % \end{macrocode} % % \subsection{Create Pseudocode/Procedure Commands} % % \begin{macrocode} % % parameter reordering \def\@pseudocodeB#1#2[#3]#4{\setkeys*{pcspace}{#2,#3}\@pseudocode[head={#1#4},#2,#3]} \def\@pseudocodeC#1#2#3{\setkeys*{pcspace}{#2}\@pseudocode[head={#1#3},#2]} %for no headers \def\@pseudocodeE#1#2[#3]{\setkeys*{pcspace}{#2,#3}\@pseudocode[head={#1},#2,#3]} \def\@pseudocodeF#1#2{\setkeys*{pcspace}{#2}\@pseudocode[head={#1},#2]} % % \end{macrocode} % %\begin{macro}{\createprocedurecommand} % Define pseudocode command with parameters: % \begin{enumerate} % \item name % \item code to execute after begingroup % \item head prefix % \item other config % \end{enumerate} % \begin{macrocode} \newcommand*{\@pc@createproc@headmode}{text} \newcommand{\createprocedurecommand}[4]{ \expandafter\gdef\csname #1\endcsname{% \begingroup% \renewcommand{\@withinspaces}{false}% #2% \@ifnextchar[%] {\@pseudocodeB{#3}{#4}} {\@pseudocodeC{#3}{#4}}% }% } % \end{macrocode} %\end{macro} % % % %\begin{macro}{\createpseudocodecommand} % \begin{macrocode} \newcommand{\createpseudocodecommand}[4]{ \expandafter\gdef\csname #1\endcsname{% \begingroup% \renewcommand{\@withinspaces}{false}% #2% \@ifnextchar[%] {\@pseudocodeE{#3}{#4}} {\@pseudocodeF{#3}{#4}}% }% } % \end{macrocode} %\end{macro} % % % % % %\begin{macro}{\createpseudocodeblock} % Creates a command that has pseudocode wrapped in an |\pchstack|. % \item name % \item options for |\pchstack| % \item code to execute after begingroup % \item head prefix % \item other config % \begin{macrocode} \newcommand{\createpseudocodeblock}[5]{ \createpseudocodecommand{#1@pc}{#3}{#4}{#5} \expandafter\gdef\csname #1\endcsname{% \@ifnextchar[%] {\csname #1@@\endcsname} {\csname #1@\endcsname} }% \expandafter\gdef\csname #1@\endcsname##1{% \begin{pchstack}[#2] \csname #1@pc\endcsname{##1} \end{pchstack} } \expandafter\gdef\csname #1@@\endcsname[##1]##2{% \begin{pchstack}[#2] \csname #1@pc\endcsname[##1]{##2} \end{pchstack} } } % \end{macrocode} %\end{macro} % % % %\begin{macro}{\createprocedureblock} % Creates a command that has procedure wrapped in an |\pchstack|. % \item name % \item options for |\pchstack| % \item code to execute after begingroup % \item head prefix % \item other config % \begin{macrocode} \newcommand{\createprocedureblock}[5]{ \createprocedurecommand{#1@pc}{#3}{#4}{#5} \expandafter\gdef\csname #1\endcsname{% \@ifnextchar[%] {\csname #1@@\endcsname} {\csname #1@\endcsname} }% \expandafter\gdef\csname #1@\endcsname##1##2{% \begin{pchstack}[#2] \csname #1@pc\endcsname{##1}{##2} \end{pchstack} } \expandafter\gdef\csname #1@@\endcsname[##1]##2##3{% \begin{pchstack}[#2] \csname #1@pc\endcsname[##1]{##2}{##3} \end{pchstack} } } % \end{macrocode} %\end{macro} % % % %\begin{macro}{\procedure} %\begin{macro}{\pseudocodeblock} %\begin{macro}{\procedureblock} % Create |\procedure| command. % \begin{macrocode} \createprocedurecommand{procedure}{}{}{} \createpseudocodeblock{pseudocodeblock}{center}{}{}{} \createprocedureblock{procedureblock}{center}{}{}{} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % % % \subsection{Subprocedures} % % \begin{macrocode} % % subprocedures \newcounter{@pcsubprogcnt1} \newcounter{@pcrsubprogcnt1} \newcounter{@pcsubprogcnt2} \newcounter{@pcrsubprogcnt2} \newcounter{@pcsubprogcnt3} \newcounter{@pcrsubprogcnt3} \newcounter{@pcsubprogcnt4} \newcounter{@pcrsubprogcnt4} \newcounter{@pcsubprogcnt5} \newcounter{@pcrsubprogcnt5} \newcounter{@pcsubprogcnt6} \newcounter{@pcrsubprogcnt6} \newcounter{@pcsubprogcnt7} \newcounter{@pcrsubprogcnt7} \newcounter{@pcsubprogcnt8} \newcounter{@pcrsubprogcnt8} \newcounter{@pcsubprogcnt9} \newcounter{@pcrsubprogcnt9} \newcounter{@pcsubprogstep} \newenvironment{subprocedure}{% \addtocounter{@pcsubprogstep}{1}% % store old counter values \setcounter{@pcsubprogcnt\the@pcsubprogstep}{\value{pclinenumber}}% \setcounter{@pcrsubprogcnt\the@pcsubprogstep}{\value{pcrlinenumber}}% }{% \setcounter{pclinenumber}{\value{@pcsubprogcnt\the@pcsubprogstep}}% \setcounter{pcrlinenumber}{\value{@pcrsubprogcnt\the@pcsubprogstep}}% \addtocounter{@pcsubprogstep}{-1}} % \end{macrocode} % % \subsection{Protocols} % % \begin{macrocode} % % send message \newcommand{\pcshortmessageoffset}{0.5cm} \newcommand{\pcdefaultmessagelength}{3.5cm} \newcommand{\pcdefaultlongmessagelength}{6cm} \newcommand{\pcbeforemessageskip}{0pt} \newcommand{\pcaftermessageskip}{10pt} \newlength{\pcmessagearrow} \newcommand*\@pcsendmessagelength{\pcdefaultmessagelength} \newcommand*\@pcsendmessagecol{} \newcommand*\@pcsendmessagewidth{} \newcommand*\@pcsendmessagestyle{} \newcommand*\@pcsendmessagetop{} \newcommand*\@pcsendmessagebottom{} \newcommand*\@pcsendmessageright{} \newcommand*\@pcsendmessageleft{} \newcommand*\@pcsendmessagetopname{t} \newcommand*\@pcsendmessagebottomname{b} \newcommand*\@pcsendmessagerightname{r} \newcommand*\@pcsendmessageleftname{l} \newcommand*\@pcsendmessagetopstyle{} \newcommand*\@pcsendmessagebottomstyle{} \newcommand*\@pcsendmessagerightstyle{} \newcommand*\@pcsendmessageleftstyle{} \newcommand*\@pcsendmessagebeforeskip{\pcbeforemessageskip} \newcommand*\@pcsendmessageafterskip{\pcaftermessageskip} \define@key{pcsendmessage}{centercol}[]{\renewcommand*\@pcsendmessagecol{#1}} \define@key{pcsendmessage}{width}[]{\renewcommand*\@pcsendmessagewidth{#1}} \define@key{pcsendmessage}{style}[]{\renewcommand*\@pcsendmessagestyle{#1}} \define@key{pcsendmessage}{length}[]{\renewcommand*\@pcsendmessagelength{#1}} \define@key{pcsendmessage}{top}[]{\renewcommand*\@pcsendmessagetop{#1}} \define@key{pcsendmessage}{bottom}[]{\renewcommand*\@pcsendmessagebottom{#1}} \define@key{pcsendmessage}{right}[]{\renewcommand*\@pcsendmessageright{#1}} \define@key{pcsendmessage}{left}[]{\renewcommand*\@pcsendmessageleft{#1}} \define@key{pcsendmessage}{topname}[]{\renewcommand*\@pcsendmessagetopname{#1}} \define@key{pcsendmessage}{bottomname}[]{\renewcommand*\@pcsendmessagebottomname{#1}} \define@key{pcsendmessage}{rightname}[]{\renewcommand*\@pcsendmessagerightname{#1}} \define@key{pcsendmessage}{leftname}[]{\renewcommand*\@pcsendmessageleftname{#1}} \define@key{pcsendmessage}{topstyle}[]{\renewcommand*\@pcsendmessagetopstyle{#1}} \define@key{pcsendmessage}{bottomstyle}[]{\renewcommand*\@pcsendmessagebottomstyle{#1}} \define@key{pcsendmessage}{rightstyle}[]{\renewcommand*\@pcsendmessagerightstyle{#1}} \define@key{pcsendmessage}{leftstyle}[]{\renewcommand*\@pcsendmessageleftstyle{#1}} \define@key{pcsendmessage}{beforeskip}[]{\renewcommand*\@pcsendmessagebeforeskip{#1}} \define@key{pcsendmessage}{afterskip}[]{\renewcommand*\@pcsendmessageafterskip{#1}} \newcommand*\@pcsendmessagealignedtop{false} \define@key{pcsendmessage}{topaligned}[true]{\renewcommand*\@pcsendmessagealignedtop{#1}} \newcommand*\@pcsendmessagealignedbottom{false} \define@key{pcsendmessage}{bottomaligned}[true]{\renewcommand*\@pcsendmessagealignedbottom{#1}} \newcommand*\@pcsendmessagealignedleft{false} \define@key{pcsendmessage}{leftaligned}[true]{\renewcommand*\@pcsendmessagealignedleft{#1}} \newcommand*\@pcsendmessagealignedright{false} \define@key{pcsendmessage}{rightaligned}[true]{\renewcommand*\@pcsendmessagealignedright{#1}} \newcommand{\@pc@centerincol}[2]{% \ifmeasuring@% #2% \else% \makebox[\ifcase\expandafter #1\maxcolumn@widths\fi]{$\displaystyle#2$}% \fi% } \newcommand{\centerincol}[1]{\@pc@centerincol{\thepccolumncounter}{#1}} \newcommand{\@do@sendmessage}[1]{% \ifthenelse{\equal{\@pcsendmessagecol}{}}{% \ifthenelse{\equal{\@pcsendmessagewidth}{}}{#1}{% we have some width \makebox[\@pcsendmessagewidth]{$\displaystyle#1$}% }}{%we know the column to center on \@pc@centerincol{\@pcsendmessagecol}{#1}% }% } \newcommand*{\sendmessage}[2]{% \begingroup\setkeys{pcsendmessage}{#2}% \tikzset{PCSENDMSG-PATH-STYLE/.style/.expand once=\@pcsendmessagestyle}% \tikzset{PCSENDMSG-TOP-STYLE/.style/.expand once=\@pcsendmessagetopstyle}% \tikzset{PCSENDMSG-BOTTOM-STYLE/.style/.expand once=\@pcsendmessagebottomstyle}% \tikzset{PCSENDMSG-LEFT-STYLE/.style/.expand once=\@pcsendmessageleftstyle}% \tikzset{PCSENDMSG-RIGHT-STYLE/.style/.expand once=\@pcsendmessagerightstyle}% % % \ifthenelse{\equal{\@pcsendmessagealignedtop}{true}} {\ifthenelse{\equal{\@pcsendmessagetop}{}} {\let\@pc@fin@sendmessagetop\@pcsendmessagetop}% {\newcommand{\@pc@fin@sendmessagetop}{\let\halign\@pc@halign$\begin{aligned}\@pcsendmessagetop\end{aligned}$}}} {\let\@pc@fin@sendmessagetop\@pcsendmessagetop}% % \ifthenelse{\equal{\@pcsendmessagealignedbottom}{true}} {\ifthenelse{\equal{\@pcsendmessagebottom}{}} {\let\@pc@fin@sendmessagebottom\@pcsendmessagebottom}% {\newcommand{\@pc@fin@sendmessagebottom}{\let\halign\@pc@halign$\begin{aligned}\@pcsendmessagebottom\end{aligned}$}}} {\let\@pc@fin@sendmessagebottom\@pcsendmessagebottom}% % \ifthenelse{\equal{\@pcsendmessagealignedright}{true}} {\ifthenelse{\equal{\@pcsendmessageright}{}} {\let\@pc@fin@sendmessageright\@pcsendmessageright} {\newcommand{\@pc@finsendmessageright}{\let\halign\@pc@halign$\begin{aligned}\@pcsendmessageright\end{aligned}$}}} {\let\@pc@fin@sendmessageright\@pcsendmessageright}% % \ifthenelse{\equal{\@pcsendmessagealignedleft}{true}} {\ifthenelse{\equal{\@pcsendmessageleft}{}} {\let\@pc@fin@sendmessageleft\@pcsendmessageleft} {\newcommand{\@pc@fin@sendmessageleft}{\let\halign\@pc@halign$\begin{aligned}\@pcsendmessageleft\end{aligned}$}}} {\let\@pc@fin@sendmessageleft\@pcsendmessageleft}% %restore halign % \addtocounter{@pcsubprogstep}{1}% \hspace{\@pcsendmessagebeforeskip}% \begin{varwidth}{\linewidth} \@do@sendmessage{ \begin{tikzpicture}% \node[PCSENDMSG-LEFT-STYLE] (\@pcsendmessageleftname) {\@pc@fin@sendmessageleft}; \node[right=\@pcsendmessagelength of \@pcsendmessageleftname,PCSENDMSG-RIGHT-STYLE] (\@pcsendmessagerightname) {\@pc@fin@sendmessageright}; \path[#1,PCSENDMSG-PATH-STYLE] (\@pcsendmessageleftname) edge[] node[above,PCSENDMSG-TOP-STYLE] (\@pcsendmessagetopname) {\@pc@fin@sendmessagetop} node[below,PCSENDMSG-BOTTOM-STYLE] (\@pcsendmessagebottomname) {\@pc@fin@sendmessagebottom} (\@pcsendmessagerightname); \end{tikzpicture}% }% \end{varwidth} \addtocounter{@pcsubprogstep}{-1}% \hspace{\@pcsendmessageafterskip}% \endgroup% } \WithSuffix\newcommand\sendmessage*[2]{% \sendmessage{#1}{topaligned,leftaligned,bottomaligned,rightaligned,#2}% } \newcommandx*{\sendmessageright}[2][1=->]{% \sendmessage{#1}{#2}% } \newcommandx*{\sendmessageleft}[2][1=<-]{% \sendmessage{#1}{#2}% } \WithSuffix\newcommand\sendmessageleft*[2][\pcdefaultmessagelength]{% \begingroup% \renewcommand{\@pcsendmessagetop}{\let\halign\@pc@halign$\begin{aligned}#2\end{aligned}$}% \sendmessage{<-}{length=#1}% \endgroup% } \WithSuffix\newcommand\sendmessageright*[2][\pcdefaultmessagelength]{% \begingroup% \renewcommand{\@pcsendmessagetop}{\let\halign\@pc@halign$\begin{aligned}#2\end{aligned}$}% \sendmessage{->}{length=#1}% \endgroup% } \WithSuffix\newcommand\sendmessagerightleft*[2][\pcdefaultmessagelength]{% \begingroup% \renewcommand{\@pcsendmessagetop}{\let\halign\@pc@halign$\begin{aligned}#2\end{aligned}$}% \sendmessage{<->}{length=#1}% \endgroup% } \DeclareExpandableDocumentCommand{\sendmessagerightx}{O{\pcdefaultlongmessagelength}mO{}m}{% \multicolumn{#2}{c}{\ensuremath{\hspace{\pcbeforemessageskip}\xrightarrow[\begin{aligned}#3\end{aligned}]{\mathmakebox[#1]{\begin{aligned}#4\end{aligned}}}\hspace{\pcaftermessageskip}}} } \DeclareExpandableDocumentCommand{\sendmessageleftx}{O{\pcdefaultlongmessagelength}mO{}m}{% \multicolumn{#2}{c}{\ensuremath{\hspace{\pcbeforemessageskip}\xleftarrow[\begin{aligned}#3\end{aligned}]{\mathmakebox[#1]{\begin{aligned}#4\end{aligned}}}\hspace{\pcaftermessageskip}}} } % % Division \DeclareExpandableDocumentCommand{\pcintertext}{O{}m}{\intertext{% \ifthenelse{\equal{#1}{center}}{\makebox[\linewidth][c]{#2}}{}% \ifthenelse{\equal{#1}{dotted}}{\dotfill#2\dotfill}{}% \ifthenelse{\equal{#1}{}}{#2}{}% }\@pc@beginnewline} % \end{macrocode} % % \subsection{Tikz within Pseudocode} % % \begin{macrocode} % % remember pictues \newcounter{@pc@remember} \newcommand{\@pc@ensureremember}{% \ifthenelse{\value{@pc@remember}=0}{\tikzstyle{every picture}+=[remember picture]}{}% \addtocounter{@pc@remember}{1}} \newcommand{\@pc@releaseremember}{% \addtocounter{@pc@remember}{-1}% \ifthenelse{\value{@pc@remember}=0}{\tikzstyle{every picture}-=[remember picture]}{}% } % % pcimage \newenvironment{pcimage}{% \begingroup\@pc@ensureremember% }{% \@pc@releaseremember\endgroup% } \newcommand*\@pcnodecontent{} \newcommand*\@pcnodestyle{} \newcommand*\@pcnodedraw{} \define@key{pcnode}{content}[]{\renewcommand*\@pcnodecontent{#1}} \define@key{pcnode}{style}[]{\renewcommand*\@pcnodestyle{#1}} \define@key{pcnode}{draw}[]{\renewcommand*\@pcnodedraw{#1}} \newcommandx*{\pcnode}[2][2=]{% \begingroup\setkeys{pcnode}{#2}% \tikzset{PCNODE-STYLE/.style/.expand once=\@pcnodestyle}% \begin{tikzpicture}[inner sep=0ex,baseline=0pt]% \node[PCNODE-STYLE] (#1) {\@pcnodecontent}; % \end{tikzpicture}% \ifdefempty{\@pcnodedraw}{}{% \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt]\@pcnodedraw\end{tikzpicture} }% \endgroup} \newcommandx*{\pcdraw}[2][2=]{% \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#2] #1 \end{tikzpicture}} % \end{macrocode} % % \subsection{Black Box Reductions} % % \begin{macrocode} % % Reductions \newcommand{\@bb@lastbox}{} \newcommand{\@bb@lastoracle}{} \newcommand{\@bb@lastchallenger}{} \newlength{\@bb@message@voffset} \newlength{\@bb@query@voffset} \newlength{\@bb@oraclequery@voffset} \newlength{\@bb@challengerquery@voffset} \newcounter{@bb@oracle@cnt} \newcounter{@bb@oracle@nestcnt} \newcounter{@bb@challenger@cnt} \newcounter{@bb@challenger@nestcnt} \newcounter{@bb@env@nestcnt} \newcommand{\bbroraclenodenameprefix}{ora-} \newcommand{\bbrchallengernodenameprefix}{challenger-} \newcommand{\bbrenvnodenameprefix}{env-} % \end{macrocode} %\begin{macro}{aboveskip} %\begin{macro}{\@pc@bbrenvaboveskip} % \begin{macrocode} \newcommand*\@pc@bbrenvaboveskip{0pt} \define@key{pcbbrenv}{aboveskip}[0pt]{\renewcommand*\@pc@bbrenvaboveskip{#1}} % \end{macrocode} %\end{macro} %\end{macro} % % %\begin{macro}{belowskip} %\begin{macro}{\@pc@bbrenvbelowskip} % \begin{macrocode} \newcommand*\@pc@bbrenvbelowskip{0pt} \define@key{pcbbrenv}{belowskip}[0pt]{\renewcommand*\@pc@bbrenvbelowskip{#1}} % \end{macrocode} %\end{macro} %\end{macro} %\begin{macro}{\@pc@bbrenv@legacyargcheck} %\begin{macro}{\@pc@bbrenv@argstring} % ensures that first command can still be 5cm which is rewritten as aboveskip=5cm % \begin{macrocode} \newcommand*\@pc@bbrenv@argstring{} \def\@pc@bbrenv@remfinalequals#1=#2=\relax{\renewcommand*\@pc@bbrenv@argstring{#1=#2}} \def\@pc@bbrenv@legacyargcheck#1=#2\relax{% \ifthenelse{\equal{#2}{}} {\PackageWarning{cryptocode}{Deprecated option for bbrenv. Please use key value list as first parameter with keys aboveskip and/or belowskip.}% \renewcommand*\@pc@bbrenv@argstring{aboveskip=#1}} {\@pc@bbrenv@remfinalequals#1=#2\relax}% } % \end{macrocode} %\end{macro} %\end{macro} % %\begin{macro}{\bbrfirstmessageoffset} % offset of the first message from top % \begin{macrocode} \providecommand{\bbrfirstmessageoffset}{1ex} % \end{macrocode} %\end{macro} % % % %\begin{environment}{bbrenv} % Black Box Reduction Environment % \begin{macrocode} \newenvironmentx{bbrenv}[3][1={aboveskip=0pt,belowskip=0pt},3=0pt]{% \addtocounter{@bb@env@nestcnt}{1}% \renewcommand{\@bb@lastbox}{#2}% % parse args and allow old style #1=0pt \@pc@bbrenv@legacyargcheck#1=\relax% \@expandedsetkeys{pcbbrenv}{}{belowskip=#3}{\@pc@bbrenv@argstring}{}% % % reset lengths \@pc@globalsetlength{\@bb@message@voffset}{\bbrfirstmessageoffset}% \@pc@globalsetlength{\@bb@query@voffset}{\bbrfirstmessageoffset}% \@pc@globalsetlength{\@bb@oraclequery@voffset}{\bbrfirstmessageoffset}% \@pc@globalsetlength{\@bb@challengerquery@voffset}{\bbrfirstmessageoffset}% % %reset oracle counter and oracle query offset \ifthenelse{\value{@bb@oracle@nestcnt}=0} {\setcounter{@bb@oracle@cnt}{0}}{}% \ifthenelse{\value{@bb@challenger@nestcnt}=0} {\setcounter{@bb@challenger@cnt}{0}}{}% % \vspace{\@pc@bbrenvaboveskip}% \ifthenelse{\value{@bb@env@nestcnt}=1} {\@pc@ensureremember% \begin{tikzpicture} }{\tikz\bgroup} }{% \ifthenelse{\value{@bb@env@nestcnt}=1} {\end{tikzpicture}% \@pc@releaseremember% }{\egroup}% \vspace{\@pc@bbrenvbelowskip}% \addtocounter{@bb@env@nestcnt}{-1}% % reset lengths \@pc@globalsetlength{\@bb@message@voffset}{\bbrfirstmessageoffset}% \@pc@globalsetlength{\@bb@query@voffset}{\bbrfirstmessageoffset}% \@pc@globalsetlength{\@bb@oraclequery@voffset}{\bbrfirstmessageoffset}% \@pc@globalsetlength{\@bb@challengerquery@voffset}{\bbrfirstmessageoffset}% } % \end{macrocode} %\end{environment} % % % % black box reduction box % option keys % \begin{macrocode} \newcommand*\bbrboxname{} \newcommand*\bbrboxnamepos{right} \newcommand*\bbrboxnamestyle{} \newcommand*\@bbrboxnamepos{below right=0.5ex and -0.5ex of \@bb@lastbox.north east,anchor=north east} \newcommand*\bbrboxabovesep{\baselineskip} \newcommand*\@bbrboxnameposoffset{below left=\bbrboxabovesep of phantomname.south west} \newcommand*\bbrboxstyle{draw} \newcommand*\bbrboxafterskip{} \newcommand*\bbrboxminheight{0cm} \newcommand*\bbrboxminwidth{2cm} \newcommand*\bbrboxxshift{0cm} \newcommand*\bbrboxyshift{0cm} \define@key{bbrbox}{abovesep}[]{\renewcommand*\bbrboxabovesep{#1}} \define@key{bbrbox}{name}[]{\renewcommand*\bbrboxname{#1}} \define@key{bbrbox}{namestyle}[]{\renewcommand*\bbrboxnamestyle{#1}} \define@key{bbrbox}{namepos}[]{\renewcommand*\bbrboxnamepos{#1}} \define@key{bbrbox}{style}[draw]{\renewcommand*\bbrboxstyle{#1}} \define@key{bbrbox}{minwidth}[]{\renewcommand*\bbrboxminwidth{#1}} \define@key{bbrbox}{addheight}[]{\renewcommand*\bbrboxafterskip{#1}} \define@key{bbrbox}{minheight}[]{\renewcommand*\bbrboxminheight{#1}} \define@key{bbrbox}{xshift}[]{\renewcommand*\bbrboxxshift{#1}} \define@key{bbrbox}{yshift}[]{\renewcommand*\bbrboxyshift{#1}} \NewEnviron{bbrbox}[1][]{% \setkeys{bbrbox}{#1}% \ifthenelse{\equal{\bbrboxnamepos}{center}} {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north,anchor=north}}{} \ifthenelse{\equal{\bbrboxnamepos}{left}} {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north west,anchor=north west}}{} \ifthenelse{\equal{\bbrboxnamepos}{top right}} {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north east,anchor=south east}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} \ifthenelse{\equal{\bbrboxnamepos}{top center}} {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north,anchor=south}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} \ifthenelse{\equal{\bbrboxnamepos}{top left}} {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north west,anchor=south west}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} \ifthenelse{\equal{\bbrboxnamepos}{middle}} {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb@lastbox.base,anchor=south}}{} \ifthenelse{\equal{\bbrboxnamepos}{bottom}} {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb@lastbox.base,anchor=north}}{} \tikzset{BBRBOXSTYLE/.style/.expand once=\bbrboxstyle}% \tikzset{BBRBOXNAMEPOS/.style/.expand once=\@bbrboxnamepos}% \tikzset{BBRBOXNAMESTYLE/.style/.expand once=\bbrboxnamestyle}% \tikzset{BBRBOXNAMEPOSOFFSET/.style/.expand once=\@bbrboxnameposoffset}% \coordinate[inner sep=0pt,outer sep=0pt] (\@bb@lastbox-tmpouter) {}; \node at (\@bb@lastbox-tmpouter) {}; %this empty node seems needed to get the xyshift right. \node[inner sep=.3333em,anchor=north,BBRBOXSTYLE,minimum height=\bbrboxminheight,below right=\bbrboxyshift and \bbrboxxshift of \@bb@lastbox-tmpouter] (\@bb@lastbox) \bgroup \tikz{ \node[inner sep=0pt,outer sep=0pt,minimum height=0cm] (phantomname) {}; %minimum width \node[BBRBOXNAMEPOSOFFSET,minimum height=0cm] (\@bb@lastbox-inner) {\begin{varwidth}{2\linewidth}\BODY\end{varwidth}}; \ifthenelse{\equal{\bbrboxafterskip}{}}{}{ \node[below=0cm of \@bb@lastbox-inner,minimum height=\bbrboxafterskip] {}; } \node[inner sep=0pt,outer sep=0pt,at=(\@bb@lastbox-inner.south west),minimum height=0cm] () {\phantom{\hspace{\bbrboxminwidth}}}; %minimum width } \egroup; \ifthenelse{\equal{\bbrboxnamepos}{none}} {}{\node[BBRBOXNAMEPOS,BBRBOXNAMESTYLE, inner sep=0.2ex, outer sep=0pt, overlay] () {\bbrboxname};} } \newcommand*\bbroraclevdistance{\baselineskip} \newcommand*\bbroraclehdistance{1.5cm} \define@key{bbroracle}{distance}[]{\renewcommand*\bbroraclehdistance{#1}} \define@key{bbroracle}{hdistance}[]{\renewcommand*\bbroraclehdistance{#1}} \define@key{bbroracle}{vdistance}[]{\renewcommand*\bbroraclevdistance{#1}} % ORACLES \newenvironmentx{bbroracle}[2][2=]{% \begingroup \setkeys{bbroracle}{#2} %reset query boolean. This is a bit crude and does not allow nesting oracles %in oracles but should be good enough \gdef\@bbr@first@oraclequery{true} %add to nesting cout \addtocounter{@bb@oracle@nestcnt}{1} %if first oracle, then put it to the right, else stack them vertically \addtocounter{@bb@oracle@cnt}{1} \ifthenelse{\value{@bb@oracle@cnt}=1}{ \setlength{\@bb@tmplength@b}{\bbroraclevdistance-\baselineskip} \node[inner sep=0pt,below right=\@bb@tmplength@b and \bbroraclehdistance of \@bb@lastbox.north east,anchor=north west] (\bbroraclenodenameprefix#1) \bgroup }{ % compute distance of top of last box to bottom of last oracle \coordinate (@bbtmpcoord) at (\@bb@lastbox.north east); \path (@bbtmpcoord); \pgfgetlastxy{\XCoord}{\YCoordA} \coordinate (@bbtmpcoord) at (\bbroraclenodenameprefix \@bb@lastoracle.south west); \path (@bbtmpcoord); \pgfgetlastxy{\XCoord}{\YCoordB} \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB+\bbroraclevdistance} \node[inner sep=0pt,below right=\@bb@tmplength@b and \bbroraclehdistance of \@bb@lastbox.north east,anchor=north west] (\bbroraclenodenameprefix#1) \bgroup } \global\def\@bb@lastoracle{#1} \begin{bbrenv}{#1} }{ \end{bbrenv} \egroup; \addtocounter{@bb@oracle@nestcnt}{-1} \endgroup } \newcommand*\bbrchallengerhdistance{1.5cm} \newcommand*\bbrchallengervdistance{\baselineskip} \define@key{bbrchallenger}{distance}[]{\renewcommand*\bbrchallengerhdistance{#1}} \define@key{bbrchallenger}{hdistance}[]{\renewcommand*\bbrchallengerhdistance{#1}} \define@key{bbrchallenger}{vdistance}[]{\renewcommand*\bbrchallengervdistance{#1}} % Challenger \newenvironmentx{bbrchallenger}[2][2=]{% \begingroup% \setkeys{bbrchallenger}{#2}% %reset query boolean. This is a bit crude and does not allow nesting oracles %in oracles but should be good enough \gdef\@bbr@first@challengerquery{true}% %add to nesting cout \addtocounter{@bb@challenger@nestcnt}{1}% %if first oracle, then put it to the right, else stack them vertically \addtocounter{@bb@challenger@cnt}{1}% \ifthenelse{\value{@bb@challenger@cnt}=1}{% \setlength{\@bb@tmplength@b}{\bbrchallengervdistance-\baselineskip}% \node[inner sep=0pt,outer sep=0pt,below left=\@bb@tmplength@b and \bbrchallengerhdistance of \@bb@lastbox.north west,anchor=north east] (\bbrchallengernodenameprefix#1) \bgroup% }{% \coordinate (@bbtmpcoord) at (\@bb@lastbox.north west);% \path (@bbtmpcoord);% \pgfgetlastxy{\XCoord}{\YCoordA}% \coordinate (@bbtmpcoord) at (\bbrchallengernodenameprefix \@bb@lastchallenger.south east);% \path (@bbtmpcoord);% \pgfgetlastxy{\XCoord}{\YCoordB}% \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB+\bbrchallengervdistance}% \node[inner sep=0pt,below left=\@bb@tmplength@b and \bbrchallengerhdistance of \@bb@lastbox.north west,anchor=north east] (\bbrchallengernodenameprefix#1) \bgroup% }% \global\def\@bb@lastchallenger{#1} \begin{bbrenv}{#1}% }{ \end{bbrenv}% \egroup;% \addtocounter{@bb@challenger@nestcnt}{-1}% \endgroup% \let\msgfrom\bbrchallengerqueryto% } \newcommand*\bbrinputlength{0.5cm} \newcommand*\bbrinputhoffset{0.5cm} \newcommand*\bbrinputbottom{} \newcommand*\bbrinputtop{} \newcommand*\bbrinputedgestyle{} \newcommand*\bbrinputtopstyle{} \newcommand*\bbrinputbottomstyle{} \newcommand*\bbrinputnodestyle{} \newcommand*\bbrinputnodename{} \define@key{bbrinput}{length}[]{\renewcommand*\bbrinputlength{#1}} \define@key{bbrinput}{hoffset}[]{\renewcommand*\bbrinputhoffset{#1}} \define@key{bbrinput}{name}[]{\renewcommand*\bbrinputnodename{#1}} \define@key{bbrinput}{top}[]{\renewcommand*\bbrinputtop{#1}} \define@key{bbrinput}{bottom}[]{\renewcommand*\bbrinputbottom{#1}} \newcommand{\@bb@inputsetup}[1]{ %load keys \begingroup % for local keys \setkeys{bbrinput}{#1}% \tikzset{BBRINPUT-NODESTYLE/.style/.expand once=\bbrinputedgestyle}% \tikzset{BBRINPUT-TOPSTYLE/.style/.expand once=\bbrinputtopstyle}% \tikzset{BBRINPUT-BOTTOMSTYLE/.style/.expand once=\bbrinputbottomstyle}% \tikzset{BBRINPUT-EDGESTYLE/.style/.expand once=\bbrinputedgestyle}% } \newcommand{\@bb@inputfinalize}{ \endgroup } \newcommandx*{\bbrinput}[2][2=]{% \@bb@inputsetup{#2} \ifthenelse{\equal{\bbrinputnodename}{}} {\renewcommand{\bbrinputnodename}{\@bb@lastbox-input}}{} \node[overlay,above right={\bbrinputlength} and {\bbrinputhoffset} of \@bb@lastbox.north west, anchor=south,BBRINPUT-NODESTYLE] (\bbrinputnodename) {#1}; \path[->] (\bbrinputnodename.south) edge[BBRINPUT-EDGESTYLE] node[above,anchor=east,BBRINPUT-TOPSTYLE] () {\bbrinputtop} node[below,anchor=west,BBRINPUT-BOTTOMSTYLE] () {\bbrinputbottom} (\bbrinputnodename.south|-\@bb@lastbox.north); \@bb@inputfinalize } \newcommandx*{\bbroutput}[2][2=]{% \@bb@inputsetup{#2} \ifthenelse{\equal{\bbrinputnodename}{}} {\renewcommand{\bbrinputnodename}{\@bb@lastbox-output}}{} \node[overlay,below right={\bbrinputlength} and {\bbrinputhoffset} of \@bb@lastbox.south west, anchor=north] (\bbrinputnodename) {#1}; \draw[->] (\bbrinputnodename.north|-\@bb@lastbox.south) -- (\bbrinputnodename.north|-\bbrinputnodename.north); \@bb@inputfinalize } \newenvironment{bbrpic}[1][]{% \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#1]% }{% \end{tikzpicture}} % % communication %temporary lengths \newlength{\@bb@com@tmpoffset} \newlength{\@bb@tmplength@b} %keys \newcommand*\@bbrcomsidestyle{} \newcommand*\@bbrcomosidestyle{} \newcommand*\@bbrcomtopstyle{} \newcommand*\@bbrcombottomstyle{} \newcommand*\@bbrcomside{} \newcommand*\@bbrcomoside{} \newcommand*\@bbrcomtop{} \newcommand*\@bbrcombottom{} \newcommand*\@bbrcomedgestyle{} \newcommand*\@bbrcomlength{1.25cm} \newcommand*\@bbrcomtopname{bbrcomtop} \newcommand*\@bbrcombottomname{bbrcombottom} \newcommand*\@bbrcomsidename{bbrcomside} \newcommand*\@bbrcomosidename{bbrcomoside} \newcommand*\@bbrcombeforeskip{0pt} \newcommand*\@bbrcomafterskip{0ex} \define@key{bbrcom}{sidestyle}[]{\renewcommand*\@bbrcomsidestyle{#1}} \define@key{bbrcom}{osidestyle}[]{\renewcommand*\@bbrcomosidestyle{#1}} \define@key{bbrcom}{topstyle}[]{\renewcommand*\@bbrcomtopstyle{#1}} \define@key{bbrcom}{bottomstyle}[]{\renewcommand*\@bbrcombottomstyle{#1}} \define@key{bbrcom}{side}[]{\renewcommand*\@bbrcomside{#1}} \define@key{bbrcom}{oside}[]{\renewcommand*\@bbrcomoside{#1}} \define@key{bbrcom}{top}[]{\renewcommand*\@bbrcomtop{#1}} \define@key{bbrcom}{bottom}[]{\renewcommand*\@bbrcombottom{#1}} \define@key{bbrcom}{edgestyle}[]{\renewcommand*\@bbrcomedgestyle{#1}} \define@key{bbrcom}{length}[]{\renewcommand*\@bbrcomlength{#1}} \define@key{bbrcom}{topname}[]{\renewcommand*\@bbrcomtopname{#1}} \define@key{bbrcom}{bottomname}[]{\renewcommand*\@bbrcombottomname{#1}} \define@key{bbrcom}{sidename}[]{\renewcommand*\@bbrcomsidename{#1}} \define@key{bbrcom}{osidename}[]{\renewcommand*\@bbrcomosidename{#1}} \define@key{bbrcom}{beforeskip}[]{\renewcommand*\@bbrcombeforeskip{#1}} \define@key{bbrcom}{aboveskip}[]{\renewcommand*\@bbrcombeforeskip{#1}} \define@key{bbrcom}{afterskip}[]{\renewcommand*\@bbrcomafterskip{#1}} \define@key{bbrcom}{belowskip}[]{\renewcommand*\@bbrcomafterskip{#1}} % \end{macrocode} %\begin{macro}{\@bbrcomfixedoffset} %\begin{macro}{\@bbrcomfixedboffset} %\begin{macro}{fixedoffset} %\begin{macro}{fixedboffset} % Provide means for fixed message offset from top or bottom % \begin{macrocode} \newcommand*\@bbrcomfixedoffset{} \newcommand*\@bbrcomfixedboffset{false} \define@key{bbrcom}{fixedoffset}[]{\renewcommand*\@bbrcomfixedoffset{#1}} \define@key{bbrcom}{fixedboffset}[]{\renewcommand*\@bbrcomfixedoffset{#1}\renewcommand*\@bbrcomfixedboffset{true}} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \begin{macrocode} % % \newcommand*\@bbrbasenodestyle{} \newcommand*\@bbrbasenodename{bbrtmpname} \define@key{bbrabase}{nodestyle}[]{\renewcommand*\@bbrbasenodestyle{#1}} \define@key{bbrabase}{nodename}[]{\renewcommand*\@bbrbasenodename{#1}} \newcommand*\@bbr@first@msg{true} \newcommand*\@bbr@first@query{true} \newcommand*\@bbr@first@oraclequery{true} \newcommand*\@bbr@first@challengerquery{true} % \end{macrocode} % % %\begin{macro}{\@bbr@intermessage@skip} %\begin{macro}{\@bbr@intermessage@medskip} %\begin{macro}{\@bbr@intermessage@shortskip} %\begin{macro}{\@bbr@intermessage@veryshortskip} % Skip between two messages. % \begin{macrocode} \newcommand*\@bbr@intermessage@skip{4ex} \newcommand*\@bbr@intermessage@veryshortskip{1ex} \newcommand*\@bbr@intermessage@shortskip{1.5ex} \newcommand*\@bbr@intermessage@medskip{2.5ex} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{islast} %\begin{macro}{\@bbrcomislast} % Sets the message from the bottom of the box with the same distance as the first message. % \begin{macrocode} \newcommand*\@bbrcomislast{false} \define@key{bbrcom}{islast}[true]{\renewcommand*\@bbrcomislast{#1}} \newcommand*\@bbrcom@check@islast{% \ifthenelse{\equal{\@bbrcomislast}{true}} {\renewcommand*\@bbrcomfixedoffset{\bbrfirstmessageoffset}\renewcommand*\@bbrcomfixedboffset{true}} {} } % \end{macrocode} %\end{macro} %\end{macro} % % % %\begin{macro}{\@bbr@lastskip} % marker to set whether next skip is a short or a long one % \begin{macrocode} \def\@bbr@lastskip{0pt} % \end{macrocode} %\end{macro} % %\begin{macro}{\@bb@comsetup} % Sets up communication parameters for message/query commands. Parameters are % \marg{key value list}, \marg{length}, \marg{command for adding space} % \marg{true if first message} % \begin{macrocode} \newcommand{\@bb@comsetup}[4]{ % check if is first message and mark as false \edef\@tmp@bbr@isfirst{#4} \renewcommand#4{false} %load keys \begingroup % for local keys \setkeys{bbrcom}{#1}% %set styles \tikzset{BBRCOM-SIDESTYLE/.style/.expand once=\@bbrcomsidestyle}% \tikzset{BBRCOM-OSIDESTYLE/.style/.expand once=\@bbrcomosidestyle}% \tikzset{BBRCOM-TOPSTYLE/.style/.expand once=\@bbrcomtopstyle}% \tikzset{BBRCOM-BOTTOMSTYLE/.style/.expand once=\@bbrcombottomstyle}% \tikzset{BBRCOM-EDGESTYLE/.style/.expand once=\@bbrcomedgestyle}% \@bbrcom@check@islast{} % increase space #3{\@bbrcombeforeskip} \ifthenelse{\equal{\@bbrcomfixedoffset}{}} { \ifthenelse{\equal{\@tmp@bbr@isfirst}{true}} {}{#3{\@bbr@lastskip}} \setlength{\@bb@com@tmpoffset}{#2}% } { \setlength{\@bb@com@tmpoffset}{\@bbrcomfixedoffset}% } } % \end{macrocode} %\end{macro} % % %\begin{macro}{\@bb@comfinalize} % \begin{macrocode} \newcommand{\@bb@comfinalize}[1]{ #1{\@bbrcomafterskip} \endgroup \def\@bbr@lastskip{\@bbr@intermessage@skip} } % \end{macrocode} %\end{macro} % % % %\begin{macro}{\@bbrmsg} % 9 -> true if first message % 10 -> anchor from bottom % \begin{macrocode} \newcommand{\@bbrmsg}[9]{ \@bb@comsetup{#1}{#7}{#8}{#9} % \ifthenelse{\equal{\@bbrcomfixedboffset}{true}} { % from bottom \ifthenelse{\equal{#4}{north east}}{\def\@bbr@tmp@bottomanchor{south east}}{} \ifthenelse{\equal{#4}{north west}}{\def\@bbr@tmp@bottomanchor{south west}}{} \node[#3=-\@bb@com@tmpoffset and \@bbrcomlength of \@bb@lastbox.\@bbr@tmp@bottomanchor,anchor=#6,BBRCOM-SIDESTYLE] (\@bbrcomsidename) {\@bbrcomside}; } { % from top \node[#3=\@bb@com@tmpoffset and \@bbrcomlength of \@bb@lastbox.#4,anchor=#6,BBRCOM-SIDESTYLE] (\@bbrcomsidename) {\@bbrcomside}; } \path[#2] (\@bbrcomsidename.#6) edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\@bbrcomtopname) {\@bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\@bbrcombottomname) {\@bbrcombottom} (\@bb@lastbox.#5|-\@bbrcomsidename) -- (\@bb@lastbox.#5|-\@bbrcomsidename) node[inner sep=0pt,outer sep=0pt,BBRCOM-OSIDESTYLE] (\@bbrcomosidename) {}; % \@bb@comfinalize{#8} } % \end{macrocode} %\end{macro} % % %\begin{macro}{\bbrmsgto} %\begin{macro}{\bbrmsgfrom} %\begin{macro}{\bbrmsgtofrom} %\begin{macro}{\bbrmsgfromto} % \begin{macrocode} \newcommandx{\bbrmsgto}[1]{% \@bbrmsg{#1}{->}{below left}{north west}{west}{east}{\@bb@message@voffset}{\bbrmsgspace}{\@bbr@first@msg} } \newcommandx{\bbrmsgfrom}[1]{% \@bbrmsg{#1}{<-}{below left}{north west}{west}{east}{\@bb@message@voffset}{\bbrmsgspace}{\@bbr@first@msg} } \newcommandx{\bbrmsgtofrom}[2]{% \bbrmsgto{#1} \bbrmsgspace{-\@bbr@intermessage@skip} \bbrmsgspace{\@bbr@intermessage@shortskip} \bbrmsgfrom{#2} \bbrmsgspace{\@bbr@intermessage@medskip} } \newcommandx{\bbrmsgfromto}[2]{% \bbrmsgfrom{#1} \bbrmsgspace{-\@bbr@intermessage@skip} \bbrmsgspace{\@bbr@intermessage@shortskip} \bbrmsgto{#2} \bbrmsgspace{\@bbr@intermessage@medskip} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{\bbrmsgvdots} % \begin{macrocode} \newcommandx{\bbrmsgvdots}{% \bbrmsgtxt[xshift=\@bbrcomlength/2,afterskip=\@bbr@intermessage@skip]{$\vdots$} } % \end{macrocode} %\end{macro} % % %\begin{macro}{\bbrqryto} %\begin{macro}{\bbrqryfrom} %\begin{macro}{\bbrqrytofrom} %\begin{macro}{\bbrqryfromto} % \begin{macrocode} \newcommandx{\bbrqryto}[1]{% \@bbrmsg{#1}{<-}{below right}{north east}{east}{west}{\@bb@query@voffset}{\bbrqryspace}{\@bbr@first@query} } \newcommandx{\bbrqryfrom}[1]{% \@bbrmsg{#1}{->}{below right}{north east}{east}{west}{\@bb@query@voffset}{\bbrqryspace}{\@bbr@first@query} } \newcommand*{\bbrqrytofrom}[2]{% \bbrqryto{#1} \bbrqryspace{-\@bbr@intermessage@skip} \bbrqryspace{\@bbr@intermessage@shortskip} \bbrqryfrom{#2} \bbrqryspace{\@bbr@intermessage@medskip} } \newcommand*{\bbrqryfromto}[2]{% \bbrqryfrom{#1} \bbrqryspace{-\@bbr@intermessage@skip} \bbrqryspace{\@bbr@intermessage@shortskip} \bbrqryto{#2} \bbrqryspace{\@bbr@intermessage@medskip} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % %\begin{macro}{\@bbroracleqry} % \begin{macrocode} \newcommand{\@bbroracleqry}[4]{ \@bb@comsetup{#1}{#3}{#4}{\@bbr@first@oraclequery} % \ifthenelse{\equal{\@bbrcomfixedboffset}{true}} { % from bottom \path[#2] (\@bb@lastoracle.south west) -- ++ (0,\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt,anchor=west,BBRCOM-SIDESTYLE] (\@bbrcomsidename){\@bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\@bbrcomtopname) {\@bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\@bbrcombottomname) {\@bbrcombottom} (\@bb@lastbox.east|-\@bbrcomsidename) -- (\@bb@lastbox.east|-\@bbrcomsidename) node[inner sep=0pt,outer sep=0pt,anchor=east,BBRCOM-OSIDESTYLE] (\@bbrcomosidename) {\@bbrcomoside}; } { \path[#2] (\@bb@lastoracle.north west) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt,anchor=west,BBRCOM-SIDESTYLE] (\@bbrcomsidename){\@bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\@bbrcomtopname) {\@bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\@bbrcombottomname) {\@bbrcombottom} (\@bb@lastbox.east|-\@bbrcomsidename) -- (\@bb@lastbox.east|-\@bbrcomsidename) node[inner sep=0pt,outer sep=0pt,anchor=east,BBRCOM-OSIDESTYLE] (\@bbrcomosidename) {\@bbrcomoside}; } % \@bb@comfinalize{#4} } % \end{macrocode} %\end{macro} % % %\begin{macro}{\bbroracleqryto} %\begin{macro}{\bbroracleqryfrom} %\begin{macro}{\bbroracleqrytofrom} %\begin{macro}{\bbroracleqryfromto} % \begin{macrocode} \newcommand{\bbroracleqryfrom}[1]{ \@bbroracleqry{#1}{->}{\@bb@oraclequery@voffset}{\bbroracleqryspace} } \newcommand{\bbroracleqryto}[1]{ \@bbroracleqry{#1}{<-}{\@bb@oraclequery@voffset}{\bbroracleqryspace} } \newcommand*{\bbroracleqrytofrom}[2]{% \bbroracleqryto{#1} \bbroracleqryspace{-\@bbr@intermessage@skip} \bbroracleqryspace{\@bbr@intermessage@shortskip} \bbroracleqryfrom{#2} \bbroracleqryspace{\@bbr@intermessage@medskip} } \newcommand*{\bbroracleqryfromto}[2]{% \bbroracleqryfrom{#1} \bbroracleqryspace{-\@bbr@intermessage@skip} \bbroracleqryspace{\@bbr@intermessage@shortskip} \bbroracleqryto{#2} \bbroracleqryspace{\@bbr@intermessage@medskip} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{\@bbrchallengerqry} % \begin{macrocode} \newcommand{\@bbrchallengerqry}[4]{ \@bb@comsetup{#1}{#3}{#4}{\@bbr@first@challengerquery} % \ifthenelse{\equal{\@bbrcomfixedboffset}{true}} { \path[#2] (\@bb@lastchallenger.south east) -- ++ (0,\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt,anchor=east,BBRCOM-SIDESTYLE] (\@bbrcomsidename){\@bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\@bbrcomtopname) {\@bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\@bbrcombottomname) {\@bbrcombottom} (\@bb@lastbox.west|-\@bbrcomsidename) -- (\@bb@lastbox.west|-\@bbrcomsidename) node[inner sep=0pt,outer sep=0pt,anchor=west,BBRCOM-OSIDESTYLE] (\@bbrcomosidename) {\@bbrcomoside}; } { \path[#2] (\@bb@lastchallenger.north east) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt,anchor=east,BBRCOM-SIDESTYLE] (\@bbrcomsidename){\@bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\@bbrcomtopname) {\@bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\@bbrcombottomname) {\@bbrcombottom} (\@bb@lastbox.west|-\@bbrcomsidename) -- (\@bb@lastbox.west|-\@bbrcomsidename) node[inner sep=0pt,outer sep=0pt,anchor=west,BBRCOM-OSIDESTYLE] (\@bbrcomosidename) {\@bbrcomoside}; } % \@bb@comfinalize{#4} } % \end{macrocode} %\end{macro} % % % %\begin{macro}{\bbroracleqryto} %\begin{macro}{\bbroracleqryfrom} %\begin{macro}{\bbroracleqrytofrom} %\begin{macro}{\bbroracleqryfromto} % \begin{macrocode} \newcommand{\bbrchallengerqryfrom}[1]{ \@bbrchallengerqry{#1}{<-}{\@bb@challengerquery@voffset}{\bbrchallengerqryspace} } \newcommand{\bbrchallengerqryto}[1]{ \@bbrchallengerqry{#1}{->}{\@bb@challengerquery@voffset}{\bbrchallengerqryspace} } \newcommand*{\bbrchallengerqrytofrom}[2]{% \bbrchallengerqryto{#1} \bbrchallengerqryspace{-\@bbr@intermessage@skip} \bbrchallengerqryspace{\@bbr@intermessage@shortskip} \bbrchallengerqryfrom{#2} \bbrchallengerqryspace{\@bbr@intermessage@medskip} } \newcommand*{\bbrchallengerqryfromto}[2]{% \bbrchallengerqryfrom{#1} \bbrchallengerqryspace{-\@bbr@intermessage@skip} \bbrchallengerqryspace{\@bbr@intermessage@shortskip} \bbrchallengerqryto{#2} \bbrchallengerqryspace{\@bbr@intermessage@medskip} } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} % % % \begin{macrocode} \newcommand*\bbrcomloopleft{} \newcommand*\bbrcomloopleftstyle{} \newcommand*\bbrcomloopright{} \newcommand*\bbrcomlooprightstyle{} \newcommand*\bbrcomloopcenter{} \newcommand*\bbrcomloopcenterstyle{} \newcommand*\bbrcomloopclockwise{false} \newcommand*\bbrcomloopangle{50} \define@key{bbrcomloop}{left}[]{\renewcommand*\bbrcomloopleft{#1}} \define@key{bbrcomloop}{leftstyle}[]{\renewcommand*\bbrcomloopleftstyle{#1}} \define@key{bbrcomloop}{right}[]{\renewcommand*\bbrcomloopright{#1}} \define@key{bbrcomloop}{rightstyle}[]{\renewcommand*\bbrcomlooprightstyle{#1}} \define@key{bbrcomloop}{center}[]{\renewcommand*\bbrcomloopcenter{#1}} \define@key{bbrcomloop}{centerstyle}[]{\renewcommand*\bbrcomloopcenterstyle{#1}} \define@key{bbrcomloop}{angle}[]{\renewcommand*\bbrcomloopangle{#1}} \define@key{bbrcomloop}{clockwise}[true]{\renewcommand*\bbrcomloopclockwise{#1}} \newcommand{\bbrloop}[3]{ \begingroup % for local keys \setkeys{bbrcomloop}{#3}% \tikzset{BBRLOOP-LEFTSTYLE/.style/.expand once=\bbrcomloopleftstyle}% \tikzset{BBRLOOP-RIGHTSTYLE/.style/.expand once=\bbrcomlooprightstyle}% \tikzset{BBRLOOP-CENTERSTYLE/.style/.expand once=\bbrcomloopcenterstyle}% \ifthenelse{\equal{\bbrcomloopclockwise}{true}} { \path[->] (#1) edge[bend left=\bbrcomloopangle] node[midway,left,inner sep=0,outer sep=0,BBRLOOP-LEFTSTYLE] (bbrleft) {\bbrcomloopleft} (#2); \path[->] (#2) edge[bend left=\bbrcomloopangle] node[midway,right,inner sep=0,outer sep=0,BBRLOOP-RIGHTSTYLE] (bbrright) {\bbrcomloopright} (#1); } { \path[->] (#1) edge[bend right=\bbrcomloopangle] node[midway,left,inner sep=0,outer sep=0,] (bbrleft) {\bbrcomloopleft} (#2); \path[->] (#2) edge[bend right=\bbrcomloopangle] node[midway,right,inner sep=0,outer sep=0,] (bbrright) {\bbrcomloopright} (#1); } \node[at=($(bbrleft.west)!0.5!(bbrright.east)$),anchor=center,BBRLOOP-CENTERSTYLE]() {\bbrcomloopcenter}; \endgroup } \newcommand*\bbrintertexthoffset{1.5cm} \define@key{bbrintertext}{xshift}[]{\renewcommand*\bbrintertexthoffset{#1}} \newcommand{\@bb@intertextsetup}[1]{ %load keys \begingroup % for local keys % fix align environment (e.g. for use of pseudocode) % ^^A https://tex.stackexchange.com/questions/36954/spurious-space-above-align-environment-at-top-of-page-minipage %\pretocmd\start@align{% %\if@minipage\kern-0.5\abovedisplayskip\fi %}{}{} \setkeys{bbrcom,bbrabase,bbrintertext}{#1}% \@bbrcom@check@islast{} \tikzset{BBRBASE-NODESTYLE/.style/.expand once=\@bbrbasenodestyle}% } \newcommand{\@bb@intertextfinalize}[1]{ #1{\@bbrcomafterskip} \endgroup \def\@bbr@lastskip{\@bbr@intermessage@veryshortskip} } % \end{macrocode} %\begin{macro}{\@bbrintertext} % 7 -> whether or not this is the first msg/query % \begin{macrocode} \newcommand{\@bbrintertext}[7]{ \edef\@tmp@bbr@isfirst{#7} \renewcommand#7{false} \@bb@intertextsetup{#1} % increase space #5{\@bbrcombeforeskip} \ifthenelse{\equal{\@bbrcomfixedoffset}{}} { \ifthenelse{\equal{\@tmp@bbr@isfirst}{true}} {}{#5{\@bbr@intermessage@veryshortskip}} \setlength{\@bb@com@tmpoffset}{#4}% } { \setlength{\@bb@com@tmpoffset}{\@bbrcomfixedoffset}% } % \ifthenelse{\equal{\@bbrcomfixedboffset}{true}} { % from bottom \ifthenelse{\equal{#3}{north east}}{\def\@bbr@tmp@bottomanchor{south east}}{} \ifthenelse{\equal{#3}{north west}}{\def\@bbr@tmp@bottomanchor{south west}}{} \node[#2=-\@bb@com@tmpoffset and \bbrintertexthoffset of \@bb@lastbox.\@bbr@tmp@bottomanchor, inner sep=0, outer sep=0, BBRBASE-NODESTYLE] (\@bbrbasenodename) {#6}; } { \node[#2=\@bb@com@tmpoffset and \bbrintertexthoffset of \@bb@lastbox.#3, inner sep=0, outer sep=0, BBRBASE-NODESTYLE] (\@bbrbasenodename) {#6}; } % % compute height of node \coordinate (@bbtmpcoord) at (\@bbrbasenodename.north); \path (@bbtmpcoord); \pgfgetlastxy{\XCoord}{\YCoordA} \coordinate (@bbtmpcoord) at (\@bbrbasenodename.south); \path (@bbtmpcoord); \pgfgetlastxy{\XCoord}{\YCoordB} % update voffset \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB} #5{\the\@bb@tmplength@b} \@bb@intertextfinalize{#5} } % \end{macrocode} %\end{macro} % \begin{macrocode} \newcommand{\bbrmsgtxt}[2][]{ \@bbrintertext{#1}{below left}{north west}{\@bb@message@voffset}{\bbrmsgspace}{#2}{\@bbr@first@msg} } \newcommand{\bbrqrytxt}[2][]{ \@bbrintertext{#1}{below right}{north east}{\@bb@query@voffset}{\bbrqryspace}{#2}{\@bbr@first@query} } \newcommand{\bbrchallengertxt}[2][]{ \begingroup \setlength{\@bb@tmplength@b}{\bbrchallengerhdistance/2}% \renewcommand{\bbrintertexthoffset}{\the\@bb@tmplength@b}% \@bbrintertext{#1}{below left}{north west}{\@bb@challengerquery@voffset}{\bbrchallengerqryspace}{#2}{\@bbr@first@challengerquery} \endgroup } \newcommand{\bbroracletxt}[2][]{ \begingroup \setlength{\@bb@tmplength@b}{\bbroraclehdistance/2}% \renewcommand{\bbrintertexthoffset}{\the\@bb@tmplength@b}% \@bbrintertext{#1}{below left}{north west}{\@bb@oraclequery@voffset}{\bbroracleqryspace}{#2}{\@bbr@first@oraclequery} \endgroup } \newcommand{\bbrmsgspace}[1]{ \@pc@globaladdtolength{\@bb@message@voffset}{#1} } \newcommand{\bbrqryspace}[1]{ \@pc@globaladdtolength{\@bb@query@voffset}{#1} } \newcommand{\bbroracleqryspace}[1]{ \@pc@globaladdtolength{\@bb@oraclequery@voffset}{#1} } \newcommand{\bbrchallengerqryspace}[1]{ \@pc@globaladdtolength{\@bb@challengerquery@voffset}{#1} } % \end{macrocode} % % \subsection{Game-Based Proofs} % % \begin{macrocode} \newcounter{pcstartgamecounter} % % % \end{macrocode} % % %\begin{macro}{gamechange} % Highlighting of changes between games. Highlight color can be set via % |\gamechangecolor| % \begin{macrocode} \definecolor{gamechangecolor}{gray}{0.90} \newcommand{\gamechange}[2][gamechangecolor]{% {\setlength{\fboxsep}{0pt}\colorbox{#1}{\ifmmode$\displaystyle#2$\else#2\fi}}% } % \end{macrocode} %\end{macro} % %\begin{macro}{\pcbox} % A simple box for conditional (ie., boxed) lines. % \begin{macrocode} \newcommand{\pcbox}[1]{% {\setlength{\fboxsep}{3pt}\fbox{$\displaystyle#1$}} } % \end{macrocode} %\end{macro} % % % % %\begin{macro}{\pcgame} %\begin{macro}{\pcgamename} %\begin{macro}{\pcgameprocedurestyle} % \begin{macrocode} \newcommand*{\pcgamename}{Game} \newcommand*{\pcgameprocedurestyle}[1]{\ensuremath{\mathsf{#1}}} \def\pcgame{\bgroup\pcgame@} \newcommand{\pcgame@}[1][]{\ifthenelse{\equal{#1}{}}{\pcgame@@}{\pcgame@@@{#1}}} \def\pcgame@@{\pcgameprocedurestyle{\pcgamename}\egroup} \def\pcgame@@@#1{\ensuremath{\pcgameprocedurestyle{\pcgamename_{\normalfont{#1}}}}\egroup} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % % %\begin{macro}{\@pc@gametitle} % Creates the header/title of a game % \begin{macrocode} \newcommand\@pc@gametitle[1][]{\ifthenelse{\equal{#1}{}} {\ensuremath{\pcgame[\thepcgamecounter]\gameprocedurearg}} {\ensuremath{\pcgame[#1]\gameprocedurearg}}} % \end{macrocode} %\end{macro} % %\begin{macro}{\gameprocedurearg} % \begin{macrocode} \newcommand*{\gameprocedurearg}{\ensuremath{(\secpar)}} % \end{macrocode} %\end{macro} % % %\begin{environment}{gameproof} % \begin{macrocode} \newcommand*\@pcgameproofgamenr{0} \define@key{pcgameproof}{nr}[]{\renewcommand*\@pcgameproofgamenr{#1}} \define@key{pcgameproof}{name}[]{\renewcommand*\pcgamename{\ensuremath{#1}}} \define@key{pcgameproof}{arg}[]{\renewcommand*\gameprocedurearg{\ensuremath{#1}}} \newenvironment{gameproof}[1][]{% \begingroup% \setkeys{pcgameproof}{#1}% \@pc@ensureremember% \setcounter{pcgamecounter}{\@pcgameproofgamenr}% \setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}% }{\@pc@releaseremember\endgroup} % \end{macrocode} %\end{environment} % % % % \begin{macrocode} \newcommand{\setgameproceduredefaultstyle}[1]{% \PackageWarning{cryptocode}{Deprecated command setgameproceduredefaultstyle. Use pcsetargs instead.}% \pcsetargs{#1}} \createpseudocodecommand{gameprocedure} {\addtocounter{pcgamecounter}{1}\renewcommand{\@withingame}{true}} {\@pc@gametitle} {} \def\@bxgame@pseudocodeA[#1]#2#3{\setkeys*{pcspace}{#1}\renewcommand{\@bxgameheader}{\@pc@gametitle[#2]}% \@pseudocode[head=\@pc@gametitle,#1]{#3}} \def\@bxgame@pseudocodeB#1#2{\renewcommand{\@bxgameheader}{\@pc@gametitle[#1]}% \@pseudocode[head=\@pc@gametitle]{#2}} \newcommand{\bxgameprocedure}{ \begingroup% \renewcommand{\@withinspaces}{false}% \renewcommand{\@withingame}{true}% \renewcommand{\@withinbxgame}{true}% \stepcounter{pcgamecounter}% \@ifnextchar[%] {\@bxgame@pseudocodeA} {\@bxgame@pseudocodeB}% } \newcommand{\@pc@secondheader}{} %tbx top boxed \createpseudocodecommand{tbxgameprocedure} {\addtocounter{pcgamecounter}{1}\renewcommand{\@withingame}{true}% \renewcommand{\@pc@secondheader}{true}} {\@pc@gametitle} {} \newcommand*\@pcgamehopnodestyle{} \newcommand*\@pcgamehopedgestyle{bend left} \newcommand*\@pcgamehoppathestyle{} \newcommand*\@pcgamehophint{} \newcommand*\@pcgamehophintbelow{} \newcommand*\@pcgamehopinhint{} \newcommand*\@pcgamehoplength{1.5cm} \define@key{pcgamehop}{nodestyle}[]{\renewcommand*\@pcgamehopnodestyle{#1}} \define@key{pcgamehop}{edgestyle}[]{\renewcommand*\@pcgamehopedgestyle{#1}} \define@key{pcgamehop}{pathstyle}[]{\renewcommand*\@pcgamehoppathestyle{#1}} \define@key{pcgamehop}{hint}[]{\renewcommand*\@pcgamehophint{#1}} \define@key{pcgamehop}{belowhint}[]{\renewcommand*\@pcgamehophintbelow{#1}} \define@key{pcgamehop}{inhint}[]{\renewcommand*\@pcgamehopinhint{#1}} \define@key{pcgamehop}{length}[]{\renewcommand*\@pcgamehoplength{#1}} \newcommand{\@pc@setupgamehop}[1]{ \begingroup\setkeys{pcgamehop}{#1}% \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% \tikzset{GAMEHOP-EDGE-STYLE/.style/.expand once=\@pcgamehopedgestyle}% } \newcommand{\@pc@finalizegamehop}{ \endgroup } \newcommandx*{\addgamehop}[3]{% \begingroup% \ifthenelse{#1<#2}% {\ifthenelse{\equal{\@withingamedescription}{true}}% {\renewcommand*\@pcgamehopedgestyle{bend right=20}\renewcommand*\@pcgamehopnodestyle{rotate=90}}{}% }% {\renewcommand*\@pcgamehopedgestyle{bend right}}% \@pc@setupgamehop{#3}% \begin{tikzpicture}[overlay]% \ifthenelse{#1<#2}{% \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (gamenode#2); }{% \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (bgamenode#2); }% \end{tikzpicture}% \@pc@finalizegamehop% \endgroup% } \newcommandx*{\addstartgamehop}[2][1=\thepcstartgamecounter]{% \@pc@setupgamehop{#2} \begin{tikzpicture}[overlay] \node[left=\@pcgamehoplength of gamenode#1] (tmpgamenode0) {}; \path[->,GAMEHOP-PATH-STYLE] (tmpgamenode0) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (gamenode#1); \end{tikzpicture} \@pc@finalizegamehop } \newcommandx*{\addendgamehop}[2][1=\thepcgamecounter]{% \@pc@setupgamehop{#2} \begin{tikzpicture}[overlay] \node[right=\@pcgamehoplength of gamenode#1] (tmpgamenode#1) {}; \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (tmpgamenode#1); \end{tikzpicture} \@pc@finalizegamehop } \newcommandx*{\addbxgamehop}[3]{% \@pc@setupgamehop{#3} \begin{tikzpicture}[overlay] \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE]] {\@pcgamehophint} node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (bgamenode#2); \end{tikzpicture} \@pc@finalizegamehop } \newcommandx*{\addloopgamehop}[2][1=\thepcgamecounter]{% \@pc@setupgamehop{#2} \begin{tikzpicture}[overlay] \node (looptemp1) [right=0.5cm of gamenode#1] {}; \draw[->,GAMEHOP-PATH-STYLE] (gamenode#1) -- (looptemp1|-gamenode#1) -- node[right,GAMEHOP-NODE-STYLE] {\@pcgamehophint} node[left,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (looptemp1|-bgamenode#1)-- (bgamenode#1); \end{tikzpicture} \@pc@finalizegamehop } % \end{macrocode} % % \subsubsection{Game Descriptions} % % \begin{macrocode} \newenvironment{gamedescription}[1][]{% \begingroup% \setkeys{pcgameproof}{#1} \renewcommand{\@withingamedescription}{true}% \@pc@ensureremember% \setcounter{pcgamecounter}{\@pcgameproofgamenr}% \setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}% \begin{description}% }{\end{description}\@pc@releaseremember\endgroup} \newcommandx*{\describegame}[1][1=]{% \addtocounter{pcgamecounter}{1}% \item[% \pcdraw{ \gdef\i{\thepcgamecounter}% \node[inner sep=0.0em,outer sep=0, xshift=-1ex, yshift=0.5ex] (gamenode\i) {}; }% \@pc@gametitle:]% \begingroup\setkeys{pcgamehop}{#1}% \ifthenelse{\equal{}{\@pcgamehophint}} {} {\hspace{-0.7ex}\pcdraw{%the -0.7ex is a horrible hack to fix a whitespace issue with tikz (see http://tex.stackexchange.com/questions/22873/tikzpicture-with-overlay-takes-up-space \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% \draw[->,GAMEHOP-PATH-STYLE] (gamenode\thepcgamecounter) --++ (0,-\@pcgamehoplength) node[midway,above,xshift=-1mm,rotate=90,GAMEHOP-NODE-STYLE] {\@pcgamehophint}; }}% \ifthenelse{\equal{}{\@pcgamehopinhint}} {} {\hspace{-0.7ex}\pcdraw{%the -0.7ex is a horrible hack to fix a whitespace issue with tikz (see http://tex.stackexchange.com/questions/22873/tikzpicture-with-overlay-takes-up-space \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% \draw[<-,GAMEHOP-PATH-STYLE] (gamenode\thepcgamecounter) --++ (0,\@pcgamehoplength) node[midway,above,xshift=-1mm,rotate=90,GAMEHOP-NODE-STYLE] {\@pcgamehopinhint}; }% }% \endgroup% } % % \end{macrocode} % % % % \begin{macrocode} % % \end{macrocode} %\Finale