I need both a reference and examples relevant to crypto for the TeX dialect we can use on crypto.stackexchange.com. I know there is tex.stackexchange.com but they no not even have the TeX extension enabled in their own site, nor have a tag for TeX-as-in-stackexchange, and I do not want to ask dumb questions.

Beside trial-and-error, plus reverse-engineering of other posts using "Show Math As TeX Commands", my lifebuoy is this TeX reference card (which is only very often online). But none of this tells me:

  • how to make $SHA-1(m)$ good-looking;
  • an easy reminder that integers are $\mathbb N$;
  • if the product of integers a and b should be $a \cdot b$ or something else (somewhat I dislike $ab$).

Meta is not appropriate, since TeX is not enabled, as apparent above.

Update: Paŭlo Ebermann linked to that sandbox with relevant examples. That links to mathurl which seems a nice sandbox with a few reminders, but lacks elaborate canned examples; at least now I can write $\mathtt{SHA­1}(m)$, but still that pesky - resist. Also, an issue is that entering foo in mathurl shows what $$foo$$ gives on crypto.stackexchange.com, not what $foo$ gives.

  • 3
    It looks like it is enabled on Math Stack Exchange meta, and they have a sandbox question there. If wanted, I could ask if we can enable this on crypto meta, too, for crypto-specific stuff. – Paŭlo Ebermann May 26 '12 at 10:50
  • 1
    I pinged the SE community team to see what our options are, hopefully they'll have some input for us. I think this would be a great idea, personally. – user46 May 26 '12 at 17:52
  • OK, your's is not a Wiki question. Should we migrate somewhere else and have the answer as the question or something? Or maybe you can re-phrase the question? I don't know :) – Maarten Bodewes Jul 12 at 18:34

MathJax is used to format mathematical expressions and symbols on cryptography site. You can use expressions within single dollar signs for inline math: $0101_2$ which gives and $0101_2$. Use double dollar signs for a centered block instead: $$\texttt{CAFE}_{16}$$ gives

$$\texttt{CAFE}_{16}$$

In the remainder of the text the dollar signs are not included to allow easy copying.


Braces / curly brackets {} are used to group expressions / symbols together within $\TeX$. You need to use the backslash \ escape character to use one within an expression: \{\} gives you $\{\}$. Parentheses () and (square) brackets can be used as-is, for instance in a range $[0, 10)$ is just [0, 10).

The double backslash: \\ can be used to include a line break into a longer expression that is between double dollar signs.


The following sections will show common contents of math blocks. There are however other ways of finding out how to use $\TeX$:


Identifiers

We generally use $K$ for secret keys, $P$ for public keys and $S$ for private keys (private keys are also kept secret, but they are not shared).

The letter $N$ is generally used for the modulus while $n$ is used for the block size. $k$ is the key size.

Greek symbols are referenced by name, prefixed with a slash, for instance \alpha for $\alpha$ or \pi for $\phi$. Start with a capital to have the larger variant if available: \Phi for $\Phi$.

Undefined functions

Most cryptographic functions are undefined in the $\TeX$ packages; it is however important to make sure they are not confused with identifiers.

Use \text H or \text{hash} for hashing: $\text H$ or $\text{hash}$. The standing text separates the functions from the variables. Officially \operatorname should be used instead of \text but the latter behaves similarly and is much shorter. To use a specific function over a message use \text{SHA-1}(M) which gives $\text{SHA-1}(M)$. Note that you may have to escape some characters with a backslash when using text as it directly quotes the argument.

For big-O it is probably best to use \text{O}(n) for $\text{O}(n)$ (or \mathcal{O}(n) which shows as $\mathcal{O}(n)$ if you think that looks nicer).

For a function definition like $F: \Bbb R \to \Bbb Z_n, \quad x \mapsto {\lfloor x\rfloor}^2\bmod n$
one can use F: \Bbb R \to \Bbb Z_n, \quad x \mapsto {\lfloor x\rfloor}^2\bmod n.

Predefined functions

There are some predefined functions that are useful for cryptography.

  • \Pr(X) for probability of X happening $\Pr(X)$
  • \log_2(x) gives you logarithm base two: $\log_2(x)$
  • others are \gcd, \exp, \ln and so on; for those missing (no \lcm), see above.

Sub- and superscript

  • just A gives you $A$
  • P_A gives you $P_A$
  • P^2 gives you $P^2$
  • combined: P_A^2 gives $P_A^2$ while {P_A}^2 gives ${P_A}^2$ and P_{A^2} gives $P_{A^2}$
  • P' gives you $P'$, and P_A'' gives you $P_A''$
  • \widetilde{P} can be used for ephemeral (temporary) variables: $\widetilde{P}$
  • \overline{P} for (usually) a complementing variable: $\overline{P}$

Bit-ops

Bit operations can be shown like this:

  • bitwise XOR: x \oplus y gives you $x \oplus y$
  • bitwise AND: x \wedge y gives you $x \wedge y$
    alternatively, x \mathbin\& y gives you $x \mathbin\& y$ (note the backslash escape)
  • bitwise OR: x \vee y gives $x \vee y$
    alternatively, x \mathbin| y gives you $x \mathbin| y$
  • negation: \neg x gives you $\neg x$
  • left shift: use x \ll n for $x \ll n$
  • right shift: use x \gg n for $x \gg n$
  • left rotate: use x \lll n for $x \lll n$
  • right rotate: use x \ggg n for $x \ggg n$

Simple math

  • addition: x + y gives you $x + y$
  • subtraction: x - y gives you $x - y$
  • multiplication: x \cdot y gives you $x \cdot y$
  • division: x / y gives you $x / y$
  • modulo: x \bmod n gives you $x \bmod n$
  • power: x ^ y gives you $x ^ y$
  • square root: \sqrt{x} gives you $\sqrt{x}$
  • nth root: \sqrt[n]{x} gives you $\sqrt[n]{x}$

For an equation holding modulo $n$, use x \equiv y \pmod n for $x \equiv y \pmod n$.

You may also want to use division with a divider line using \frac, for instance c \cdot \frac {x + y} z: $$c \cdot \frac {x + y} z$$

Floor and ceiling requires some addition work as the common symbols are very small: \big\lceil x \big\rceil gives you $\big\lceil x \big\rceil$. Replace by \lfloor and \rfloor for the other function.

To multiply vectors or sets it may be wise to chose A \times B over the \cdot notation giving you $A \times B$.

Comparison

  • x = y is equality $x = y$
  • x \neq y is non-equality $x \neq y$
  • x < y is less-than $x < y$ (no need to escape or use &lt; within dollar signs)
  • x \leq y is less-than-or-equal $x \leq y$ (just \le also seems to work)
  • x \equiv y is equivalence $x \equiv y$
  • X \implies Y is used to show implication: $X \implies Y$ , sometime X \to Y for $X \to Y$
  • X \iff Y is used to show equivalence: $X \iff Y$

It is possible to prefix anything with \not to negate the next symbol, e.g. \not\leq is $\not\leq$

Sets, groups

  • \{ 0, 1 \} gives the two-elements set $\{ 0, 1 \}$
  • \emptyset gives the empty set $\emptyset$
  • A \cup B and A \cap B give $A \cup B$ (union) and $A \cap B$ (intersection)
  • a \in A gives $a \in A$, while b \not\in A gives $b \not\in A$
  • A \subset B or A \subseteq B give $A \subset B$ or $A \subseteq B$
  • Standard sets are formatted using \mathbb{N} or \Bbb N for short, giving $\Bbb N$
  • (\Bbb Z_n,+) gives $(\Bbb Z_n,+)$, the additive group modulo $n$
  • \Bbb Z_n^* gives $\Bbb Z_n^*$, the integers coprime to $n$

Others

  • M \mathbin \| N is concatenation of strings: $M\mathbin\|N$
  • To indicate failure the \bot (bottom) sign is often used: $\bot$
  • \ldots gives you something that hasn't been finished: $\ldots$
  • and, finally, \square is used for Q.E.D. $\square$
  • Please edit above. But keep to the format and order of the contents the same. Note that these are formatting hints; there is no need to explain the operations that are described. – Maarten Bodewes Jul 4 at 10:53
  • @fgrieu Could you try and change the above without making it too hard to understand for the other users? I agree with above points, but calling \bmod modulo and \pmod remainder is not very clear and the explanation was correct but also hard to read, so I reverted for the sake of readability. – Maarten Bodewes Jul 13 at 12:55
  • OK for a Keep It Simple and Short policy, I tried to apply that in my latest edit. This comment is enough to state that $x=y\bmod n$ implies $0\le x<n$ (because \bmodis the remainder operator), when $x\equiv y\pmod n$ leaves $x$ unbounded (because the pair \equiv \pmod indicates equivalence modulo); and to note the ambiguity on that point of $x=y\pmod n$ and $x\equiv y\mod n$ and $x=y\mod n$, which thus should be avoided at least when the difference matters. – fgrieu Jul 13 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .