summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/cryptocode
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-03-24 21:18:29 +0000
committerKarl Berry <karl@freefriends.org>2015-03-24 21:18:29 +0000
commit5aeb41ca04c8e1569d208402993903b5f0440be9 (patch)
treeb76fac3b05a66e400a17c83b5e00a653cc692948 /Master/texmf-dist/tex/latex/cryptocode
parent1b9aa95deee3641bd94fd7589b3ebe1e84f87103 (diff)
cryptocode (24mar15)
git-svn-id: svn://tug.org/texlive/trunk@36612 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cryptocode')
-rw-r--r--Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty1406
1 files changed, 1406 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty b/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty
new file mode 100644
index 00000000000..1e1b843dfce
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty
@@ -0,0 +1,1406 @@
+ %% Copyright 2015 Arno Mittelbach
+ %
+ % This work may be distributed and/or modified under the
+ % conditions of the LaTeX Project Public License, either version 1.3
+ % of this license or (at your option) any later version.
+ % The latest version of this license is in
+ % http://www.latex-project.org/lppl.txt
+ % and version 1.3 or later is part of all distributions of LaTeX
+ % version 2005/12/01 or later.
+ %
+ % This work has the LPPL maintenance status `maintained'.
+ %
+ % The Current Maintainer of this work is Arno Mittelbach.
+ %
+ % This work consists of the files cryptocode.tex and cryptocode.sty
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{cryptocode}
+ [2015/03/09 v0.01 Cryptocode LaTeX package for writing pseudocode in cryptographic settings]
+
+
+\def\hi{Hello, this is Arno's crypto code package. }
+\let\myDate\date
+
+%%%
+% option modes
+\newif\ifpc@orderofgrowth
+\newif\ifpc@algorithmstyle
+\newif\ifpc@amsfonts
+\newif\ifpc@advantage
+\newif\ifpc@primitives
+
+%%%
+%
+\DeclareOption{operators}{
+ \providecommand{\sample}{\hskip2.3pt{\gets\!\!\mbox{\tiny${\$}$\normalsize}}\,}
+
+ \providecommand{\floor}[1]{\ensuremath{\left\lfloor #1\right\rfloor}}
+ \providecommand{\ceil}[1]{\ensuremath{\left\lceil #1\right\rceil}}
+ \providecommand{\Angle}[1]{\ensuremath{\left\langle #1\right\rangle}}
+ \providecommand{\abs}[1]{\ensuremath{\left\lvert #1 \right\rvert}}
+ \providecommand{\norm}[1]{\ensuremath{\left\|#1\right\|}}
+ \providecommand{\concat}{\ensuremath{\|}}
+
+ \providecommand{\emptystring}{\ensuremath{\varepsilon}}
+}
+
+\DeclareOption{adversary}{
+ \providecommand{\pcadvstyle}[1]{\mathcal{#1}}
+
+ \providecommand{\adv}{\ensuremath{\pcadvstyle{A}}}
+ \providecommand{\bdv}{\ensuremath{\pcadvstyle{B}}}
+ \providecommand{\cdv}{\ensuremath{\pcadvstyle{C}}}
+ \providecommand{\ddv}{\ensuremath{\pcadvstyle{D}}}
+ \providecommand{\mdv}{\ensuremath{\pcadvstyle{M}}}
+ \providecommand{\pdv}{\ensuremath{\pcadvstyle{P}}}
+ \providecommand{\rdv}{\ensuremath{\pcadvstyle{R}}}
+ \providecommand{\sdv}{\ensuremath{\pcadvstyle{S}}}
+}
+
+\DeclareOption{landau}{
+ \pc@orderofgrowthtrue
+
+ \providecommand{\bigO}[1]{\ensuremath{\mathcal{O}\olrk{#1}}}
+ \providecommand{\smallO}[1]{\ensuremath{\text{o}\olrk{#1}}}
+ \providecommand{\bigOmega}[1]{\ensuremath{\Omega\olrk{#1}}}
+ \providecommand{\smallOmega}[1]{\ensuremath{\omega\olrk{#1}}}
+ \providecommand{\bigsmallO}[1]{\ensuremath{\Theta\olrk{#1}}}
+}
+
+\DeclareOption{probability}{
+ \pc@orderofgrowthtrue
+ \pc@amsfontstrue
+
+ \providecommand{\probname}{Pr}
+ \providecommand{\expectationname}{\ensuremath{\mathbb{E}}}
+ \providecommand{\supportname}{Supp}
+
+ \providecommand{\prob}[1]{\ensuremath{\operatorname{\probname}\elrk{#1}}}
+ \providecommand{\probsub}[2]{\ensuremath{\operatorname{\probname}_{#1}\elrk{#2}}}
+ \providecommand{\condprob}[2]{\ensuremath{\prob{#1\,\left|\,#2\vphantom{#1}\right.}}}
+ \providecommand{\condprobsub}[3]{\ensuremath{\probsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}}
+
+ \providecommand{\expect}[1]{\ensuremath{\operatorname{\expectationname}\elrk{#1}}}
+ \providecommand{\expsub}[2]{\ensuremath{\operatorname{\expectationname}_{#1}\elrk{#2}}}
+ \providecommand{\condexp}[2]{\ensuremath{\expect{#1\,\left|\,#2\vphantom{#1}\right.}}}
+ \providecommand{\condexpsub}[3]{\ensuremath{\expsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}}
+
+ \providecommand{\supp}[1]{ \ensuremath{\operatorname{Supp}\olrk{#1}}}
+
+ \providecommand{\entropy}[1]{\ensuremath{\operatorname{H}\olrk{#1}}}
+ \providecommand{\minentropy}[1]{\ensuremath{\operatorname{H_\infty}\olrk{#1}}}
+ \providecommand{\condminentropy}[2]{\ensuremath{\operatorname{\tilde{H}_\infty}\olrk{#1|#2}}}
+}
+
+\DeclareOption{sets}{
+ \pc@orderofgrowthtrue
+ \pc@amsfontstrue
+
+ \providecommand\NN{\mathbb{N}}
+ \providecommand\ZZ{\mathbb{Z}}
+ \providecommand\QQ{\mathbb{Q}}
+ \providecommand\RR{\mathbb{R}}
+ \providecommand\PP{\mathbb{P}}
+ \providecommand\FF{\mathbb{F}}
+ \providecommand\GG{\mathbb{G}}
+
+ \providecommand{\set}[1]{\ensuremath{\clrk{#1}}}
+ \providecommand{\sequence}[1]{\ensuremath{\olrk{#1}}}
+ \providecommand{\bin}{\ensuremath{\{0,1\}}}
+}
+
+\DeclareOption{noamsfonts}{
+ \pc@amsfontsfalse
+}
+
+
+\DeclareOption{notions}{
+ \providecommand{\pcnotionstyle}[1]{\ensuremath{\mathrm{#1}}}
+
+ \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}}
+}
+
+\DeclareOption{logic}{
+ \providecommand{\AND}{\ensuremath{\mathrm{AND}}}
+ \providecommand{\OR}{\ensuremath{\mathrm{OR}}}
+ \providecommand{\NOT}{\ensuremath{\mathrm{NOT}}}
+ \providecommand{\xor}{\ensuremath{\oplus}}
+ \providecommand{\false}{\mathsf{false}}
+ \providecommand{\true}{\mathsf{true}}
+}
+
+
+% Function Families
+\DeclareOption{ff}{
+ \pc@algorithmstyletrue
+
+ \providecommand{\kgen}{\pcalgostyle{KGen}}
+ \providecommand{\pgen}{\pcalgostyle{Pgen}}
+ \providecommand{\eval}{\pcalgostyle{Eval}}
+
+ \providecommand{\il}{\pcalgostyle{il}}
+ \providecommand{\ol}{\pcalgostyle{ol}}
+ \providecommand{\kl}{\pcalgostyle{kl}}
+ \providecommand{\nl}{\pcalgostyle{nl}}
+ \providecommand{\rl}{\pcalgostyle{rl}}
+}
+
+% Machine Model
+\DeclareOption{mm}{
+ \pc@algorithmstyletrue
+
+ \providecommand{\pcmachinemodelstyle}[1]{\ensuremath{\mathsf{#1}}}
+
+ \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}}
+}
+
+\DeclareOption{advantage}{
+ \pc@advantagetrue
+}
+
+\DeclareOption{primitives}{
+ \pc@primitivestrue
+ \pc@algorithmstyletrue
+}
+
+\DeclareOption{events}{
+ \providecommand{\event}[1]{\ensuremath{\mathsf{#1}}}
+ \providecommand{\nevent}[1]{\ensuremath{\overline{\event{#1}}}}
+
+ \providecommand{\bad}{\ensuremath{\event{bad}}}
+}
+
+\DeclareOption{complexity}{
+ \providecommand{\pccomplexitystyle}[1]{\ensuremath{\mathsf{#1}}}
+
+ \providecommand{\npol}{\pccomplexitystyle{NP}}
+ \providecommand{\conpol}{\ensuremath{\mathsf{co}}\pccomplexitystyle{NP}}
+ \providecommand{\pol}{\pccomplexitystyle{P}}
+ \providecommand{\bpp}{\pccomplexitystyle{BPP}}
+ \providecommand{\ppoly}{\ensuremath{\pol/\mathrm{poly}}}
+
+ \providecommand{\AM}{\pccomplexitystyle{AM}}
+ \providecommand{\coAM}{\ensuremath{\mathsf{co}}\pccomplexitystyle{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}}}}
+}
+
+\DeclareOption{asymptotics}{
+ \pc@orderofgrowthtrue
+
+ \providecommand{\pcpolynomialstyle}[1]{\mathsf{#1}}
+
+ \providecommand{\negl}[1][\secpar]{\ensuremath{\pcpolynomialstyle{negl}\ifthenelse{\equal{#1}{}}{}{\olrk{#1}}}}
+ \providecommand{\poly}[1][\secpar]{\ensuremath{\pcpolynomialstyle{poly}\ifthenelse{\equal{#1}{}}{}{\olrk{#1}}}}
+
+ \providecommand{\pp}{\ensuremath{\pcpolynomialstyle{p}}}
+ \providecommand{\qq}{\ensuremath{\pcpolynomialstyle{q}}}
+}
+
+\DeclareOption{keys}{
+ \providecommand{\pckeystyle}[1]{\ensuremath{\mathsf{#1}}}
+
+ \providecommand{\pk}{\pckeystyle{pk}}
+ \providecommand{\vk}{\pckeystyle{vk}}
+ \providecommand{\sk}{\pckeystyle{sk}}
+ \providecommand{\key}{\pckeystyle{k}}
+ \providecommand{\hk}{\pckeystyle{hk}}
+ \providecommand{\gk}{\pckeystyle{gk}}
+ \providecommand{\fk}{\pckeystyle{fk}}
+
+ \providecommand{\st}{\pckeystyle{st}}
+ \providecommand{\state}{\pckeystyle{state}}
+}
+
+\DeclareOption{n}{
+ \providecommand{\secpar}{\ensuremath{n}}
+ \providecommand{\secparam}{\ensuremath{1^\secpar}}
+}
+
+\DeclareOption{lambda}{
+ \providecommand{\secpar}{\ensuremath{\lambda}}
+ \providecommand{\secparam}{\ensuremath{1^\secpar}}
+}
+
+\DeclareOption*{%
+ \PackageError{crypto code}{Unknown option ‘\CurrentOption’}%
+}
+
+\ExecuteOptions{n}
+
+\ProcessOptions\relax
+
+%amsfonts
+\RequirePackage{amsmath}
+\ifpc@amsfonts
+ \RequirePackage{amsfonts}
+\fi
+\RequirePackage{mathtools}
+\RequirePackage{xcolor}
+\RequirePackage{calc}
+\RequirePackage{tikz}
+\usetikzlibrary{positioning,calc}
+\RequirePackage{ifthen}
+\RequirePackage{xargs}
+\RequirePackage{pgf}
+\RequirePackage{mathabx}
+\RequirePackage{forloop}
+\RequirePackage{array}
+\RequirePackage{xparse}
+\RequirePackage{pbox}
+\RequirePackage{varwidth}
+\RequirePackage{suffix}
+\RequirePackage{etoolbox}
+\RequirePackage{etex}
+\RequirePackage{etextools}
+\RequirePackage{environ}
+\RequirePackage{xstring}
+\RequirePackage{xspace}
+\RequirePackage{xkeyval}
+
+\ifpc@advantage
+ \newcommandx*{\advantage}[3][3=(\secpar)]{\ensuremath{\mathsf{Adv}^{\mathrm{\MakeLowercase{#1}}}_{#2}#3}}
+\fi
+
+\ifpc@primitives
+ % zero knowledge
+ \providecommand{\prover}{\pcalgostyle{P}}
+ \providecommand{\verifier}{\pcalgostyle{V}}
+ \providecommand{\nizk}{\pcalgostyle{NIZK}}
+
+ % hash
+ \providecommand{\hash}{\pcalgostyle{H}}
+ \providecommand{\gash}{\pcalgostyle{G}}
+ \providecommand{\fash}{\pcalgostyle{F}}
+
+ % encryption
+ \providecommand{\enc}{\pcalgostyle{Enc}}
+ \providecommand{\dec}{\pcalgostyle{Dec}}
+
+ % signatures
+ \providecommand{\sig}{\pcalgostyle{Sig}}
+ \providecommand{\verify}{\pcalgostyle{Vf}}
+
+ % obfuscation
+ \providecommand{\obf}{\pcalgostyle{O}}
+ \providecommand{\iO}{\pcalgostyle{iO}}
+ \providecommand{\diO}{\pcalgostyle{diO}}
+
+ % PRF, PRG
+ \providecommand{\prf}{\pcalgostyle{PRF}}
+ \providecommand{\prg}{\pcalgostyle{PRG}}
+
+ % Mac
+ \providecommand{\mac}{\pcalgostyle{MAC}}
+
+ % puncture
+ \providecommand{\puncture}{\pcalgostyle{Puncture}}
+
+ % Misc
+ \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}}
+\fi
+
+%%
+% math hyphen
+\mathchardef\pcmathhyphen ="2D
+
+%%%
+% order of growth helper
+\ifpc@orderofgrowth
+ \providecommand{\olrk}[1]{%
+ \ifx\nursymbol#1\else\!\!\mskip4.5mu plus 0.5mu\left(#1\right)\fi}
+ \providecommand{\elrk}[1]{%
+ \ifx\nursymbol#1\else%
+ \!\!\mskip4.5mu plus0.5mu\left[\mskip2.5mu plus0.5mu #1\right]\fi}
+ \providecommand{\clrk}[1]{%
+ \ifx\nursymbol#1\else%
+ \!\!\mskip4.5mu plus0.5mu\left\{\mskip2.5mu plus0.5mu #1\right\}\fi}
+\fi
+
+\ifpc@algorithmstyle
+ \providecommand{\pcalgostyle}[1]{\ensuremath{\mathsf{#1}}}
+\fi
+
+%%%
+% create command to measure width of align
+%
+\newcommand{\@settowidthofalign}[2]{%
+ \setbox\z@=\vbox{
+ \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{\@settowidthofaligned}[2]{%
+ \settowidth{#1}{$\begin{aligned}#2\end{aligned}$}
+}
+
+
+% run stuff in an empty box
+\newcommand{\@pcexecuteblindly}[1]{%
+ \setbox\z@=\vbox{#1 }}
+
+% copy label command
+\AtBeginDocument{
+ \let\pc@original@label\ltx@label
+}
+
+
+%%%%%%
+\newcommand*{\@pc@globaladdtolength}[2]{%
+\addtolength{#1}{#2}%
+\global#1=#1\relax}
+
+\newcommand*{\@pc@globalsetlength}[2]{%
+\setlength{#1}{#2}%
+\global#1=#1\relax}
+
+
+
+% The size to be used by the pseudocode procedure
+\providecommand{\pcsize}{\small}
+% The size to be used by the pseudocode procedure when writing subprocedures
+\providecommand{\pcsubsize}{\footnotesize}
+
+%%%%%
+% spaces before and after pseudo codes (left and right)
+\providecommand{\beforepcskip}{2pt}
+\providecommand{\afterpcskip}{0pt}
+
+%%%
+% a global counter of the number of times the pseudocode command was triggered
+\newcounter{@pc@global@pc@cnt}
+\newcounter{@pc@global@pc@nestcnt}
+
+%%%
+% Fix hyperref package.. gnarl http://tex.stackexchange.com/questions/130319/incompatibility-between-etoolbox-and-hyperref
+\providecommand{\pcfixhyperref}{
+\global\let\textlabel\label
+\global\let\pc@original@label\textlabel
+%\global\let\pc@original@label\relax
+%\global\let\label\relax
+}
+
+%%%%%%%%
+% line numbers
+%%%%%%%%
+% The following commands handle line numbering within the pseudocode command. The
+% pseudocode command itself does need to do some counter magic
+\newcounter{pclinenumber}
+\newcounter{Hpclinenumber} % make hyperref happy
+\newcounter{@pclinenumbertmp}
+\newcounter{pcgamecounter}
+\newcounter{Hpcgamecounter}
+\newcounter{pcrlinenumber}
+\newcounter{Hpcrlinenumber}
+\newcounter{@pcrlinenumbertmp}
+
+% separators
+\providecommand{\pclnseparator}{:}
+\providecommand{\pcrlnseparator}{\hspace{1pt}}
+
+% spacing for linenumbers
+\providecommand{\pclnspace}{0pt}
+\providecommand{\pclnrspace}{5pt}
+
+% left align line numbers
+\providecommand{\pcln}[1][]{%
+\refstepcounter{pclinenumber}%
+\stepcounter{Hpclinenumber}%
+\ifthenelse{\equal{#1}{}}{}{%
+%keep hyperref happy
+\ifmeasuring@\else\pc@original@label{#1}\fi%
+}%
+\hspace{\pclnspace}\text{\scriptsize\arabic{pclinenumber}}\pclnseparator\quad}%
+
+
+% right align line numbers (same counter)
+\providecommand{\pclnr}{%
+\refstepcounter{pclinenumber}%
+\quad\text{\scriptsize\pcrlnseparator\arabic{pclinenumber}}\hspace{5pt}}
+
+% right align line numbers different counter
+\providecommand{\pcrln}{
+\refstepcounter{pcrlinenumber}%
+\stepcounter{Hpcrlinenumber}%
+\text{\scriptsize\pcrlnseparator\arabic{pcrlinenumber}}\hspace{\pclnrspace}}
+
+
+%%%
+% indentation
+\newlength{\@pcindentwidth}
+\providecommand{\pcind}[1][1]{%
+\setlength{\@pcindentwidth}{\widthof{\ensuremath{\quad}}*#1}%
+\ensuremath{\mathmakebox[\@pcindentwidth]{}}}
+
+
+% create length
+\newlength{\@pc@minipage@length}
+\newlength{\@pc@alt@minipage@length}
+
+% backward games
+\newif\ifbxgame
+\newcommand{\@bxgameheader}{}
+
+
+%%%%%%%%%%%%
+% The pseudocode Command
+%%%%%
+\newlength{\@pc@length@tmp@width@vstack}
+
+
+\newcommand{\@pc@beginnewline}{\@pc@and\@pseudocodelinenumber\@pc@modebegin}
+\newcommand{\@pc@and}{&}
+\newcommand{\@pc@and@wrap@end}{\@pc@modeend&}
+\newcommand{\@pc@and@wrap@start}{\@pc@beginnewline}
+\newcommand{\pctabname}{>}
+\newcommand{\pcdbltabname}{<}
+\newcommand{\pcindentname}{t}
+
+
+
+\newcommand*\@pseudocodehead{}
+\newcommand*\@pseudocodewidth{}
+\newcommand*\@pseudocodexshift{0pt}
+\newcommand*\@pseudocodelinenumber{}
+\newcommand*\@pseudocodebeforeskip{0ex}
+\newcommand*\@pseudocodeafterskip{0ex}
+\newcommand*\@pseudocodelnstart{0}
+\newcommand*\@pseudocodelnstartright{0}
+\newcommand*\@pseudocodesyntaxhighlighting{}
+\newcommand*\@pseudocodekeywords{for ,foreach ,return ,{ do }, in ,new ,if ,null ,null,true ,true,until ,{ to },false ,false,{ then },repeat ,else ,done ,done,fi }
+\newcommand*\@pseudocodeaddkeywords{}
+\define@key{pseudocode}{head}[]{\renewcommand*\@pseudocodehead{#1}}
+\define@key{pseudocode}{width}[]{\renewcommand*\@pseudocodewidth{#1}}
+\define@key{pseudocode}{xshift}[]{\renewcommand*\@pseudocodexshift{#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}{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 \ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}%
+\def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}%
+}%
+\renewcommand*\@pc@modeend{\end{varwidth}}
+}{}%
+}
+\define@key{pseudocode}{keywords}[]{\renewcommand*\@pseudocodekeywords{#1}}
+\define@key{pseudocode}{addkeywords}[]{\renewcommand*\@pseudocodeaddkeywords{#1}}
+\define@key{pseudocode}{syntaxhighlight}[]{\renewcommand*\@pseudocodesyntaxhighlighting{#1}}
+
+\newcommand{\@pc@modebegin}{}
+\newcommand{\@pc@modeend}{}
+\newcommand{\@pc@thecontent}{}
+
+\newcommand{\@pc@syntaxhighlight}[1]{%
+\ifthenelse{\equal{\@pseudocodesyntaxhighlighting}{auto}}{%
+\saveexploremode\expandarg % suppress expansions made by xstring
+\def\@shtmp{#1}% first step
+\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodeaddkeywords}%
+\foreach \@pckw in \@tmpkeywords{%
+\ifthenelse{\equal{\@pckw}{}}{}{%
+\StrSubstitute{\@pckw}{ }{PCXXMYBREAKSPACE}[\@pckwspace]% take care of spaces
+\StrSubstitute{\@shtmp}{\@pckw}{\expandafter\@pc@highlight\expandafter{\@pckwspace}}[\@shtmpA]%
+\global\let\@shtmp\@shtmpA%
+}}%
+\restoreexploremode\@shtmp%
+}{#1}%
+}
+
+\newcommand{\@pc@highlight}[1]{%
+\StrSubstitute{#1}{PCXXMYBREAKSPACE}{}[\@pctmpname]%
+\StrSubstitute{#1}{PCXXMYBREAKSPACE}{ }[\@pctmporg]%
+\StrSubstitute{#1}{PCXXMYBREAKSPACE}{~}[\@pctmpres]%
+\ifcsname dohighlight\@pctmpname\endcsname%
+\csname dohighlight\@pctmpname\endcsname{\@pctmporg}%
+\else\pseudocodeconstant[]{\@pctmpres}\fi%
+}
+
+% store original halign
+\let\@pc@halign\halign%
+
+
+\providecommand{\pseudocode}[2][]{%
+\begingroup%
+\setkeys{pseudocode}{#1}%
+\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@modebegin}%
+\else%
+\expandafter\newcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@modebegin}%
+\fi%
+\ifcsname \pcdbltabname\endcsname%
+\expandafter\renewcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@modebegin}%
+\else%
+\expandafter\newcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@modebegin}%
+\fi%
+% create indent command
+\expandafter\let\csname \pcindentname\endcsname\pcind%
+% wrap content if necessary
+\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}}%
+%
+%
+% line magic
+\ifthenelse{\value{@pc@global@pc@nestcnt}=1}{%
+\let\@pc@halign\halign%
+\def\halign{%
+\renewcommand{\label}[1]{\ifmeasuring@\else\pc@original@label{####1}\fi}%
+\let\@pc@lb\\%
+\renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and \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}{0em}%
+%
+% if no width is set compute width and store in circuitlength
+\ifthenelse{\equal{\@pseudocodewidth}{}}{%
+% compute length of pseudocode
+\ifthenelse{\value{@pcsubprogstep}=0}{%
+\@settowidthofalign{\@pc@minipage@length}{\@pc@thecontent}%
+}{%
+\@settowidthofaligned{\@pc@minipage@length}{\@pc@thecontent}%
+}%
+%compute length of header
+\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}{5pt}%
+}{\addtolength{\@pc@minipage@length}{\@pseudocodewidth}}%
+% reset counter
+\setcounter{pclinenumber}{\value{@pclinenumbertmp}}%
+\setcounter{pcrlinenumber}{\value{@pcrlinenumbertmp}}%
+% begin actual output
+%
+%
+%do the actual mini page
+\hspace{\@pseudocodexshift}%
+\begin{minipage}[t]{\@pc@minipage@length}%
+\ifthenelse{\value{@pcsubprogstep}=0}{%
+\pc@display@pseudocode{\@pseudocodehead}{\@pc@thecontent}%
+}{% if sub procedure
+\pc@display@subcode{\@pseudocodehead}{\@pc@thecontent}%
+}%
+\end{minipage}%
+\hspace{\afterpcskip}%
+% tikz usage
+\@pc@releaseremember%
+\addtocounter{@pc@global@pc@nestcnt}{-1}%
+\endgroup%
+}
+
+
+\let\pclb\relax
+%
+\newcommand{\pc@display@pseudocode}[2]{%
+\ifthenelse{\equal{#1}{}}{\vspace{-0.8\baselineskip}\pcsize}{%
+\tikz{\gdef\i{\thepcgamecounter}%
+\node[anchor=base] (gamenode\i) {\hspace{-2pt}#1\vphantom{$\sum^A_{A_b}$}};
+\ifbxgame\node[draw,anchor=base, above=0.1cm of gamenode\i] (bgamenode\i) {\@bxgameheader\vphantom{$\sum^A_{A_b}$}};\fi %
+}\vspace{-0.1\baselineskip}\hrule\small\vspace{-0.5\baselineskip}}%
+\begin{flalign*} #2 \end{flalign*}
+}
+
+
+\newcommand{\pc@display@subcode}[2]{%
+\begingroup%
+\ifthenelse{\equal{#1}{}}{}{#1\vphantom{$\sum^A_{A_b}$}\hrule \vspace{0.2\baselineskip}}%
+\pcsubsize%
+$\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
+}
+
+
+%%%%%%%%%%%%%%%%%%%
+% 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}[1]{%
+\begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt]
+#1
+\end{tikzpicture}}
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%
+% Reductions
+\newcommand{\@bb@lastbox}{}
+\newcommand{\@bb@lastoracle}{}
+
+\newlength{\@bb@message@hoffset}
+\newlength{\@bb@query@hoffset}
+\newlength{\@bb@oraclequery@hoffset}
+
+\newcounter{@bb@oracle@cnt}
+\newcounter{@bb@oracle@nestcnt}
+\newcounter{@bb@env@nestcnt}
+
+\newcommand{\bbroraclenodenameprefix}{ora-}
+\newcommand{\bbrenvnodenameprefix}{env-}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Black Box Reduction Enviconment
+\newenvironmentx{bbrenv}[3][1=0pt,3=0pt]{
+\addtocounter{@bb@env@nestcnt}{1}
+\renewcommand{\@bb@lastbox}{#2}
+
+% reset lengths
+\setlength{\@bb@message@hoffset}{0pt}
+\setlength{\@bb@query@hoffset}{0pt}
+\@pc@globalsetlength{\@bb@oraclequery@hoffset}{0pt}
+
+%reset oracle counter and oracle query offset
+\ifthenelse{\value{@bb@oracle@nestcnt}=0}{
+ \setcounter{@bb@oracle@cnt}{0}
+}{
+}
+
+\def\@bbendskip{#3}
+\vspace{#1}
+\ifthenelse{\value{@bb@env@nestcnt}=1}{
+\@pc@ensureremember
+\begin{tikzpicture}
+}{\tikz\bgroup}
+}{
+\ifthenelse{\value{@bb@env@nestcnt}=1}{
+\end{tikzpicture}
+\@pc@releaseremember
+}{\egroup}
+\vspace{\@bbendskip}
+\addtocounter{@bb@env@nestcnt}{-1}
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% black box reduction box
+% option keys
+\newcommand*\bbrboxname{}
+\newcommand*\bbrboxstyle{draw}
+\newcommand*\bbrboxafterskip{}
+\newcommand*\bbrboxxshift{-2cm}
+\define@key{bbrbox}{name}[]{\renewcommand*\bbrboxname{#1}}
+\define@key{bbrbox}{style}[draw]{\renewcommand*\bbrboxstyle{#1}}
+\define@key{bbrbox}{minheight}[]{\renewcommand*\bbrboxafterskip{#1}}
+\define@key{bbrbox}{xshift}[]{\renewcommand*\bbrboxxshift{#1}}
+
+
+\NewEnviron{bbrbox}[1][]{%
+\setkeys{bbrbox}{#1}%
+
+\tikzset{BBRBOXSTYLE/.style/.expand once=\bbrboxstyle}%
+\node[inner sep=0pt,outer sep=0pt] (bbrshift) {};
+\node[BBRBOXSTYLE,xshift=\bbrboxxshift] (\@bb@lastbox) at (bbrshift) \bgroup
+ \tikz{
+ \node (inner) {\begin{varwidth}{\linewidth}\BODY\end{varwidth}};
+ \node[right=0.05cm of inner.north east] (tmpne) {};
+ \node[above left=0.cm and 0pt of tmpne.north] (name) {\bbrboxname};
+ \ifthenelse{\equal{\bbrboxafterskip}{}}{}{
+ \node[below=0cm of inner,minimum height=\bbrboxafterskip] {};
+ }
+ }
+\egroup;
+}
+
+
+\newcommand*\bbroracledistance{1cm}
+\define@key{bbroracle}{distance}[]{\renewcommand*\bbroracledistance{#1}}
+
+% ORACLES
+\newenvironmentx{bbroracle}[2][2=]{%
+ \begingroup
+ \setkeys{bbroracle}{#2}
+ %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}{
+ \node[below right=0cm and \bbroracledistance of \@bb@lastbox.north east] (\bbroraclenodenameprefix#1) \bgroup
+ }{
+ \node[below=0.05cm of \bbroraclenodenameprefix \@bb@lastoracle.south west, anchor=north west] (\bbroraclenodenameprefix#1) \bgroup
+ }
+ \global\def\@bb@lastoracle{#1}
+ \begin{bbrenv}{#1}
+}{
+ \end{bbrenv}
+ \egroup;
+
+ \addtocounter{@bb@oracle@nestcnt}{-1}
+ \endgroup
+}
+
+\newcommandx{\bbrinput}[2][1=0.75cm]{%
+\node[above right=#1 of \@bb@lastbox.north west] (input) {#2};
+\draw[->] (input) --++ (0,-0.75cm);
+}
+
+\newcommandx{\bbroutput}[2][1=0.75cm]{%
+\node[below right=#1 of \@bb@lastbox.south west] (output) {#2};
+\draw[<-] (output) --++ (0,#1);
+}
+
+%%%%%%%%%%%
+% communication
+%temporary lengths
+\newlength{\@bb@com@tmpoffset}
+\newlength{\@bb@tmplength@b}
+\newcommand{\@bb@firstmessageheight}{-0.15cm}
+\newcommand{\@bb@msglength}{1.25cm}
+\newcommand{\@bb@qrylength}{1.5cm}
+
+%keys
+\newcommand*\bbrcomnsidestyle{}
+\newcommand*\bbrcomtopstyle{}
+\newcommand*\bbrcombottomstyle{}
+\newcommand*\bbrcomside{}
+\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{0pt}
+\define@key{bbrcom}{sidestyle}[]{\renewcommand*\bbrcomnsidestyle{#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}{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}{afterskip}[]{\renewcommand*\bbrcomafterskip{#1}}
+
+\newcommand*\bbrbasenodestyle{}
+\newcommand*\bbrbasenodename{bbrtmpname}
+\define@key{bbrabase}{nodestyle}[]{\renewcommand*\bbrbasenodestyle{#1}}
+\define@key{bbrabase}{nodename}[]{\renewcommand*\bbrbasenodename{#1}}
+
+
+\newcommand{\@bb@comsetup}[3]{
+ %load keys
+ \begingroup % for local keys
+
+ \setkeys{bbrcom}{#1}%
+
+ %set styles
+ \tikzset{BBRCOM-SIDESTYLE/.style/.expand once=\bbrcomnsidestyle}%
+ \tikzset{BBRCOM-TOPSTYLE/.style/.expand once=\bbrcomtopstyle}%
+ \tikzset{BBRCOM-BOTTOMSTYLE/.style/.expand once=\bbrcombottomstyle}%
+ \tikzset{BBRCOM-EDGESTYLE/.style/.expand once=\bbrcomedgestyle}%
+
+ % increase space
+ #3\baselineskip
+ \ifthenelse{\equal{\bbrcomtop}{}}{}{#3\baselineskip}
+
+ \setlength{\@bb@com@tmpoffset}{#2+\@bb@firstmessageheight+\bbrcombeforeskip}%
+}
+
+\newcommand{\@bb@comfinalize}[1]{
+ \ifthenelse{\equal{\bbrcombottom}{}}{}{#1{\baselineskip}}
+ #1{\bbrcomafterskip}
+ \endgroup
+}
+
+\newcommand{\@bbrmsg}[7]{
+ \@bb@comsetup{#1}{#6}{#7}
+ %
+ \node[#3=\@bb@com@tmpoffset and \bbrcomlength of \@bb@lastbox.#4,BBRCOM-SIDESTYLE] (\bbrcomsidename) {\bbrcomside};
+ \path[#2] (\bbrcomsidename) edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.#5|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {};
+ %
+ \@bb@comfinalize{#7}
+}
+
+\newcommandx{\bbrmsgto}[1]{%
+\@bbrmsg{#1}{->}{below left}{north west}{west}{\@bb@message@hoffset}{\bbrmsgspace}
+}
+\newcommandx{\bbrmsgfrom}[1]{%
+\@bbrmsg{#1}{<-}{below left}{north west}{west}{\@bb@message@hoffset}{\bbrmsgspace}
+}
+\newcommandx{\bbrqryto}[1]{%
+\@bbrmsg{#1}{<-}{below right}{north east}{east}{\@bb@query@hoffset}{\bbrqryspace}
+}
+\newcommandx{\bbrqryfrom}[1]{%
+\@bbrmsg{#1}{->}{below right}{north east}{east}{\@bb@query@hoffset}{\bbrqryspace}
+}
+
+\newcommand{\@bbroracleqry}[4]{
+ \@bb@comsetup{#1}{#3}{#4}
+ %
+
+ \path[#2] (\@bb@lastoracle.north west) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.east|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {};
+ %
+ \@bb@comfinalize{#4}
+}
+
+\newcommand{\bbroraclequeryfrom}[1]{
+ \@bbroracleqry{#1}{->}{\@bb@oraclequery@hoffset}{\bbroracleqryspace}
+}
+
+\newcommand{\bbroraclequeryto}[1]{
+ \@bbroracleqry{#1}{<-}{\@bb@oraclequery@hoffset}{\bbroracleqryspace}
+}
+
+
+\newcommand*\bbrcomloopleft{}
+\newcommand*\bbrcomloopright{}
+\newcommand*\bbrcomloopcenter{}
+\define@key{bbrcomloop}{left}[]{\renewcommand*\bbrcomloopleft{#1}}
+\define@key{bbrcomloop}{right}[]{\renewcommand*\bbrcomloopright{#1}}
+\define@key{bbrcomloop}{center}[]{\renewcommand*\bbrcomloopcenter{#1}}
+
+\newcommand{\bbrloop}[3]{
+ \begingroup % for local keys
+ \setkeys{bbrcomloop}{#3}%
+
+ \path[->] (#1) edge[bend right=50] node[left] (bbrleft) {\bbrcomloopleft} (#2);
+ \path[->] (#2) edge[bend right=50] node[right] (bbrright) {\bbrcomloopright} (#1);
+ \node () at ($(bbrleft)!0.5!(bbrright)$) {\bbrcomloopcenter};
+
+ \endgroup
+}
+
+\newcommand*\bbrintertexthoffset{1.5cm}
+\define@key{bbrintertext}{xshift}[]{\renewcommand*\bbrintertexthoffset{#1}}
+
+\newcommand{\@bb@intertextsetup}[1]{
+ %load keys
+ \begingroup % for local keys
+
+ \setkeys{bbrcom,bbrabase,bbrintertext}{#1}%
+
+ \tikzset{BBRBASE-NODESTYLE/.style/.expand once=\bbrbasenodestyle}%
+}
+
+\newcommand{\@bb@intertextfinalize}[1]{
+ #1{\bbrcomafterskip}
+ \endgroup
+}
+
+\newcommand{\@bbrintertext}[6]{
+ \@bb@intertextsetup{#1}
+
+ %introduce space
+ #5{\baselineskip}
+
+ %compute offset
+ \setlength{\@bb@com@tmpoffset}{#4+\@bb@firstmessageheight+\bbrcombeforeskip}%
+
+ %
+ \node[#2=\@bb@com@tmpoffset and \bbrintertexthoffset of \@bb@lastbox.#3,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 hoffset
+ \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB}
+ #5{\the\@bb@tmplength@b}
+
+ \@bb@intertextfinalize{#5}
+}
+
+\newcommand{\bbrmsgtxt}[2][]{
+ \@bbrintertext{#1}{below left}{north west}{\@bb@message@hoffset}{\bbrmsgspace}{#2}
+}
+
+\newcommand{\bbrqrytxt}[2][]{
+ \@bbrintertext{#1}{below right}{north east}{\@bb@query@hoffset}{\bbrqryspace}{#2}
+}
+
+\newcommand{\bbrmsgspace}[1]{
+\@pc@globaladdtolength{\@bb@message@hoffset}{#1}
+}
+
+\newcommand{\bbrqryspace}[1]{
+\@pc@globaladdtolength{\@bb@query@hoffset}{#1}
+}
+
+\newcommand{\bbroracleqryspace}[1]{
+\@pc@globaladdtolength{\@bb@oraclequery@hoffset}{#1}
+}
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% stacking
+\providecommand{\pccenteraboveskip}{0.5\baselineskip}
+\providecommand{\pccenterbelowskip}{0.5\baselineskip}
+\newenvironment{pccenter}{%
+\setlength\topsep{0pt}\setlength\parskip{0pt}%
+\begin{center}\vspace{\pccenteraboveskip}
+}{%
+\vspace{\pccenteraboveskip}%
+\end{center}}
+
+
+%%%%%%%%%%%%%%%%%%%%%
+% horizontal stacking
+% space before hstacks
+\newlength{\pcbeforehstackskip}
+
+\NewEnviron{pchstack}[1][]{%
+% write out content
+\ifthenelse{\equal{#1}{center}}{%
+\begin{pccenter}\mbox{\hspace{\pcbeforehstackskip}\BODY}\end{pccenter}}{%
+\mbox{\hspace{\pcbeforehstackskip}\BODY}}%
+}
+
+
+%%%%%%%%%%%%%%%%%%%%%%%
+\NewEnviron{pcvstack}[1][]{%
+% display minipage
+\ifthenelse{\equal{#1}{center}}{\begin{pccenter}}{}
+\begin{varwidth}[t]{15cm}\BODY\end{varwidth}
+\ifthenelse{\equal{#1}{center}}{\end{pccenter}}{}
+}
+
+
+% spacing for stacking
+\newcommand{\pchspace}[1][1em]{\hspace{#1}}
+\newcommand{\pcvspace}[1][\baselineskip]{\par\vspace{#1}}
+
+
+
+
+
+%%%%
+% 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}}
+
+
+
+%%% some basic procedure commands
+\newcommand{\pcmainname}{\textsc{Main }}
+\newcommand{\pcalgorithmname}{\textsc{Algo. }}
+\newcommand{\pccircuitname}{\textsc{Circ. }}
+\newcommand{\pcprogramname}{\textsc{Prog. }}
+\newcommand{\pcprotocolname}{\textsc{Protocol }}
+
+\providecommand{\procedure}[3][]{\pseudocode[head={#2},#1]{#3}}
+\providecommand{\mainprocedure}[3][]{\pseudocode[head={\pcmainname#2},#1]{#3}}
+\providecommand{\algorithm}[3][]{\pseudocode[head={\pcalgorithmname#2},#1]{#3}}
+\providecommand{\circuit}[3][]{\pseudocode[head={\pccircuitname#2},#1]{#3}}
+\providecommand{\program}[3][]{\pseudocode[head={\pcprogramname#2},#1]{#3}}
+\providecommand{\protocol}[3][]{\pseudocode[head={\pcprotocolname#2},#1]{#3}}
+
+
+%%%
+% 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{\centerincol}[2]{%
+\ifmeasuring@%
+#2%
+\else%
+\makebox[\ifcase\expandafter #1\maxcolumn@widths\fi]{$\displaystyle#2$}%
+\fi%
+}
+
+\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
+\centerincol{\@pcsendmessagecol}{#1}%
+}%
+}
+
+\newcommandx*{\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}%
+%restore halign
+%
+\hspace{\@pcsendmessagebeforeskip}%
+\begin{varwidth}{\linewidth}
+\@do@sendmessage{
+ \begin{tikzpicture}%
+ \node[PCSENDMSG-LEFT-STYLE] (\@pcsendmessageleftname) {\@pcsendmessageleft};
+ \node[right=\@pcsendmessagelength of \@pcsendmessageleftname,PCSENDMSG-RIGHT-STYLE] (\@pcsendmessagerightname) {\@pcsendmessageright};
+ \path[#1,PCSENDMSG-PATH-STYLE] (\@pcsendmessageleftname) edge[] node[above,PCSENDMSG-TOP-STYLE] (\@pcsendmessagetopname) {\@pcsendmessagetop} node[below,PCSENDMSG-BOTTOM-STYLE] (\@pcsendmessagebottomname) {\@pcsendmessagebottom} (\@pcsendmessagerightname);
+ \end{tikzpicture}%
+}%
+\end{varwidth}
+\hspace{\@pcsendmessageafterskip}%
+\endgroup%
+}
+
+\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%
+}
+
+
+
+\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}
+
+
+
+%%%
+% Games
+%
+\newcounter{pcstartgamecounter}
+
+\newcommand*{\pcgamename}{\ensuremath{\mathsf{Game}}}
+\newcommand*{\gameprocedurearg}{\ensuremath{(\secpar)}}
+\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}
+\bxgamefalse%
+\@pc@ensureremember%
+\setcounter{pcgamecounter}{\@pcgameproofgamenr}%
+\setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}%
+}{\@pc@releaseremember\endgroup}
+
+\newcommand{\gameprocedure}[2][]{\stepcounter{pcgamecounter}%
+\pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#2}}
+
+\newcommand{\bxgameprocedure}[3][]{%
+\renewcommand{\@bxgameheader}{$\pcgamename_{#2}$\gameprocedurearg}%
+\bxgametrue%
+\stepcounter{pcgamecounter}%
+\pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#3}%
+\bxgamefalse}
+
+\newcounter{@pc@game@tmpcnt@a}
+\newcommand{\tbxgameprocedure}[2][]{\addtocounter{pcgamecounter}{1}%
+\setcounter{@pc@game@tmpcnt@a}{\value{pcgamecounter}+1}
+\pseudocode[head={\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}%
+\ \setlength{\fboxsep}{3pt}\protect\fbox{\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}}},#1]{#2}%
+\addtocounter{pcgamecounter}{1}}
+
+
+\newcommand*\@pcgamehopnodestyle{}
+\newcommand*\@pcgamehopedgestyle{bend left}
+\newcommand*\@pcgamehoppathestyle{}
+\newcommand*\@pcgamehophint{}
+\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}{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}{}{\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} (gamenode#2);
+}{
+ \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} (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} (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} (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} (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} (looptemp1|-bgamenode#1)-- (bgamenode#1);
+\end{tikzpicture}
+\@pc@finalizegamehop
+}
+
+
+
+%%%%%%%%
+% basic pseudocode constants
+
+\newcommand{\pseudocodeconstant}[2][\ ]{\ensuremath{\mathbf{#2}}#1}
+
+\newcommand{\pcglobvar}{\pseudocodeconstant{gbl}}
+\newcommand{\pcnew}{\pseudocodeconstant{new}}
+\newcommand{\pcwhile}{\pseudocodeconstant{while}}
+\newcommandx*{\pcdo}[2][1=\ ,2=]{#1\pseudocodeconstant[#2]{do}}
+\newcommand{\pcif}{\pseudocodeconstant{if}}
+\newcommand{\pcelse}{\pseudocodeconstant{else}}
+\newcommand{\pcfi}{\pseudocodeconstant{fi}}
+\newcommandx*{\pcthen}[2][1=\ ,2=]{#1\pseudocodeconstant[#2]{then}}
+\newcommand{\pcreturn}{\pseudocodeconstant{return}}
+\newcommandx*{\pcin}[2][1=\ ,2=]{#1\pseudocodeconstant[#2]{in}}
+\newcommand{\pcfor}{\pseudocodeconstant{for}}
+\newcommand{\pcrepeat}[1]{\ensuremath{\pseudocodeconstant{repeat} #1\ \pseudocodeconstant{times}}}
+\newcommand{\pcrepeatuntil}[2]{\ensuremath{\pseudocodeconstant{repeat}\ #1\ \pseudocodeconstant{until}\ #2}}
+\newcommand{\pcforeach}{\pseudocodeconstant{for each}}
+\newcommand{\pcuntil}{\pseudocodeconstant{until}}
+\newcommand{\pccontinue}{\pseudocodeconstant{continue}}
+\newcommand{\pcfalse}{\pseudocodeconstant{false}}
+\newcommand{\pctrue}{\pseudocodeconstant{true}}
+\newcommand{\pcnull}{\pseudocodeconstant{null}}
+\newcommand{\pccomment}[1]{{\mbox{/\!\!/ } \text{\scriptsize#1}}}
+\newcommand{\pcdone}{\pseudocodeconstant{done}}
+\newcommand{\pcparse}{\pseudocodeconstant{parse}}
+
+%%%
+% highlighting
+\definecolor{highlight-gray}{gray}{0.90}
+\newcommand{\gamechange}[2][highlight-gray]{%
+{\setlength{\fboxsep}{0pt}\colorbox{#1}{\ifmmode$\displaystyle#2$\else#2\fi}}
+}
+
+%%%
+% boxing
+\newcommand{\pcbox}[1]{%
+{\setlength{\fboxsep}{3pt}\fbox{$\displaystyle#1$}}
+}
+
+\endinput \ No newline at end of file