3

Is there an easy (or even hard) way to draw an execution example of a cryptographic protocol? I'm trying to write about BB84 in my master's thesis, i'm looking for something like this:

enter image description here

or this:

enter image description here

I think the best way can be to use tables, but I'm really struggling. Thanks in advance!

Edit 1: As always, I forgot to put some code. Sorry!

\begin{tabular}{ |p{4cm} |p{1cm}|p{1cm}|p{1cm}||p{1cm}|  }
\hline
 & 1 & 2 & 3 & 4 \\
\hline
\textbf{(1)} Alice's bitstring & 0 & 1 & 1 & 0   \\
\textbf{(1)} Alice's bases & 1 & 1 & 0 & 0   \\
\textbf{(2)} Qubits sent & $\ket{+}$ & $\ket{-}$ & $\ket{1}$ & $\ket{0}$   \\
\textbf{(3)} Bob's bases & 1 & 0 & 1 & 0\\
\textbf{(3)} Bob's measuring results & \textbf{0} & 0 & 1 & \textbf{0}\\
\hline
\end{tabular}

The main problems are the last two rows.

2
  • 2
    Please add what you have tried so far and make your question more specific. The only thing not possible with normal tables are the boxes in the last two rows. Are you looking for a way to do that?
    – marv
    Jan 16 at 14:47
  • As always I forgot the code, added with an edit. Furthermore, you are right, the problems are the last two rows together with a formal way to represent the whole.
    – VitoShade
    Jan 16 at 15:06

1 Answer 1

6

Maybe like this:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz, array, booktabs, amsmath, amssymb}
\usetikzlibrary{arrows.meta, calc}

\tikzset{tinyarrs/.style={
    x=.5em, y=.5em, baseline=-.333em,
    every path/.style={arrows={Latex[length=2pt, width=2pt]-Latex[length=2pt, width=2pt]}}
}}

\newcommand{\nsArrow}{\tikz[tinyarrs]{
    \path(0:0)circle(1);
    \draw(90:-1)--(90:1);
}}
\newcommand{\ewArrow}{\tikz[tinyarrs]{
    \path(0:0)circle(1);
    \draw(0:-1)--(0:1);
}}
\newcommand{\nsewArrow}{\tikz[tinyarrs]{
    \path(0:0)circle(1);
    \draw(90:-1)--(90:1);
    \draw(0:-1)--(0:1);
}}
\newcommand{\acArrow}{\tikz[tinyarrs]{
    \path(0:0)circle(1);
    \draw(45:-1)--(45:1);
}}
\newcommand{\bdArrow}{\tikz[tinyarrs]{
    \path(0:0)circle(1);
    \draw(135:-1)--(135:1);
}}
\newcommand{\acbdArrow}{\tikz[tinyarrs]{
    \path(0:0)circle(1);
    \draw(45:-1)--(45:1);
    \draw(135:-1)--(135:1);
}}

\newcommand{\drawtabbox}[1][black]{%
    \tikz[overlay, remember picture]{
        \draw[#1]([shift={(-.5em,1em)}]0,0) rectangle ++({width("0")*1pt+1em},-2.66em);
    }%
}

\newcommand{\isit}{\overset{{\color{purple}?}}{=}}

\begin{document}

\begin{tabular}{ m{35pt} c c c c c c c }

\toprule

$k$ & 
    \textcolor{lightgray}{$0$} & 
    \textcolor{darkgray}{$1$} & 
    \textcolor{darkgray}{$1$} & 
    \textcolor{darkgray}{$1$} & 
    \textcolor{lightgray}{$0$} & 
    \textcolor{lightgray}{$0$} & 
    \textcolor{darkgray}{$1$} \\
    
\midrule

$b$ & 
    \textcolor{LimeGreen!50!PineGreen}{$1_{\scriptsize\acbdArrow}$} & 
    \textcolor{LimeGreen!50!PineGreen}{$1_{\scriptsize\acbdArrow}$} &
    \textcolor{CornflowerBlue!50!RoyalBlue}{$0_{\scriptsize\nsewArrow}$} &
    \textcolor{LimeGreen!50!PineGreen}{$1_{\scriptsize\acbdArrow}$} &
    \textcolor{CornflowerBlue!50!RoyalBlue}{$0_{\scriptsize\nsewArrow}$} &
    \textcolor{CornflowerBlue!50!RoyalBlue}{$0_{\scriptsize\nsewArrow}$} &
    \textcolor{CornflowerBlue!50!RoyalBlue}{$0_{\scriptsize\nsewArrow}$} \\

\scriptsize Alice \newline prepares & 
    \textcolor{LimeGreen}{\acArrow} & 
    \textcolor{PineGreen}{\bdArrow} & 
    \textcolor{RoyalBlue}{\nsArrow} & 
    \textcolor{PineGreen}{\bdArrow} & 
    \textcolor{CornflowerBlue}{\ewArrow} & 
    \textcolor{CornflowerBlue}{\ewArrow} &
    \textcolor{RoyalBlue}{\nsArrow} \\

$q$ & 
    \textcolor{LimeGreen}{$|+\rangle$} &
    \textcolor{PineGreen}{$|-\rangle$} & 
    \textcolor{RoyalBlue}{$|1\rangle$} & 
    \textcolor{PineGreen}{$|-\rangle$} & 
    \textcolor{CornflowerBlue}{$|0\rangle$} & 
    \textcolor{CornflowerBlue}{$|0\rangle$} & 
    \textcolor{RoyalBlue}{$|1\rangle$} \\

\midrule

$\tilde{b}$ &
    \textcolor{LimeGreen!50!PineGreen}{$1_{\scriptsize\acbdArrow}$} & 
    \textcolor{CornflowerBlue!50!RoyalBlue}{$0_{\scriptsize\nsewArrow}$} &
    \textcolor{CornflowerBlue!50!RoyalBlue}{$0_{\scriptsize\nsewArrow}$} &
    \textcolor{LimeGreen!50!PineGreen}{$1_{\scriptsize\acbdArrow}$} &
    \textcolor{LimeGreen!50!PineGreen}{$1_{\scriptsize\acbdArrow}$} &
    \textcolor{CornflowerBlue!50!RoyalBlue}{$0_{\scriptsize\nsewArrow}$} &
    \textcolor{LimeGreen!50!PineGreen}{$1_{\scriptsize\acbdArrow}$} \\

\scriptsize Bob \newline measures & 
    \textcolor{LimeGreen}{\acArrow} & 
    \textcolor{CornflowerBlue}{\ewArrow} & 
    \textcolor{RoyalBlue}{\nsArrow} & 
    \textcolor{PineGreen}{\bdArrow} & 
    \textcolor{LimeGreen}{\acArrow} & 
    \textcolor{CornflowerBlue}{\ewArrow} &
    \textcolor{LimeGreen}{\acArrow} \\ 

$\tilde{q}$ &
    \textcolor{LimeGreen}{$|+\rangle$} &
    \textcolor{CornflowerBlue}{$|0\rangle$} & 
    \textcolor{RoyalBlue}{$|1\rangle$} & 
    \textcolor{PineGreen}{$|-\rangle$} & 
    \textcolor{LimeGreen}{$|+\rangle$} &
    \textcolor{CornflowerBlue}{$|0\rangle$} & 
    \textcolor{LimeGreen}{$|+\rangle$} \\
    
\midrule

$\tilde{k}$ &
    \drawtabbox[purple]\textcolor{lightgray}{$0$} & 
    \textcolor{lightgray}{$0$} & 
    \drawtabbox[purple]\textcolor{darkgray}{$1$} & 
    \drawtabbox[purple]\textcolor{darkgray}{$1$} & 
    \textcolor{lightgray}{$0$} & 
    \drawtabbox[purple]\textcolor{lightgray}{$0$} & 
    \textcolor{lightgray}{$0$} \\

$b \isit \tilde{b}$ &
    \textcolor{purple}{\checkmark} & 
    \textcolor{purple}{--} & 
    \textcolor{purple}{\checkmark} & 
    \textcolor{purple}{\checkmark} & 
    \textcolor{purple}{--} & 
    \textcolor{purple}{\checkmark} & 
    \textcolor{purple}{--} \\
    
\bottomrule

\end{tabular}

\end{document}

enter image description here

1
  • Absolutely fantastic. Thank you!
    – VitoShade
    Jan 17 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.