[Tex/LaTex] How to draw protocol interaction using tikzpicture

math-modetikz-pgf

I have a question on using the tikzpicture package.

I have a protocol interaction on which two participants want to exchange some numbers, say α and β. I need bilateral arrows, and on top of it would be α and below it the β. That means these two participants are exchanging the numbers simultaneously. BTW, I don't need dots in the side of arrows, but some calculations which results in α or β must be placed there.

alt text

How can I have this output? I don't know if I have chosen the right package but it seems to me that this is the right choice.
Every sample that I have seen so far uses some dots and creates a matrix, but I don't know how to replace dots with these terms. BTW, I have no idea how can I have that arrow and even making it larger.
Any good tutorial with examples close to my need will be appreciated.

Best Answer

You don't need TikZ for this. If you're using LaTeX, you just need amsmath and the mathtools package (both of which you likely have):

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}
  \[\begin{matrix}
      x \xleftarrow{\quad R\quad} \mathcal{Z}_q            &\quad
      \xrightleftharpoons[\beta=g^y]{\quad\alpha=g^x\quad} \quad&
      y \xleftarrow{\quad R\quad} \mathcal{Z}_q            \\
      g^{xy} & & g^{xy} \\
  \end{matrix}\]
\end{document}

This produces the following output:

Extensible arrows and harpoons.

The amsmath package provides the \xleftarrow and \xrigharrow commands, which set an eXtensible \leftarrow and \righarrow, respectively; their mandatory argument is set on top, and their optional argument is set below (\xleftarrow[below]{above}). Normally, it's just as wide as necessary for the text, so I inserted \quads around the text to space it out. The mathtools package, which extends amsmath, provides more extensible arrows, including \xleftrightarrow (for an extensible ↔), \xLeftrightarrow (for an extensible ⇔), \xleftrighharpoons (for an extensible ⇋; the upside-down version of the symbol in the example picture), and \xrightleftharpoons (for an extensible ⇌, as seen in the example picture), any of which could be used here depending on your tastes.

Also, note that you shouldn't need to space out the \xrightleftharpoons like I did (which is why there's &\quad ... \quad&), but apparently I needed to here (though in LaTeXit I didn't, so with some small change you probably wouldn't need to). You only need the matrix here since you want to align the g^{xy}s with the first and third arrows; if you just wanted the top line, you wouldn't need to bother.

Related Question