# What are the equations (Gen, Enc, Dec) for the vigenere cipher?

Long story short, trying to understand how I would write the vigenere cipher mathematically when using Gen, Enc, Dec and I can't figure it out. This is what I've come up with so far.

$$\mathrm{Gen}: k ={0…25}^t$$

$$\mathrm{Enc}: c_i = (p_i + k_i) \pmod {26}$$

$$\mathrm{Dec}: p_i = (c_i – k_i) \pmod {26}$$

It doesn't really seem right though, so that's why I'm asking.

The only way I'd change it is to make it explicit that $$k$$ is sampled from that set rather than is equal to it and to note that the key is used cyclically: $$\begin{eqnarray*} \mathrm{Gen}:&&k\leftarrow \{0,\ldots,25\}^t\\ \mathrm{Enc}:&&c_i=p_i+k_{i\pmod t}\pmod{26}\\ \mathrm{Dec}:&&p_i=c_i-k_{i\pmod t}\pmod{26} \end{eqnarray*}$$
• [Retracted] Does $\gets$ unambiguously mean sampled from? I tend to use $\overset{\$}\gets$for this, and use$\gets$for affectation, where some language like Pascal use := in order to distinguish from the comparison operator. Maybe I'm wrong... – fgrieu Sep 16 at 6:28 • @fgrieu Certainly not unambiguously. Galbraith omits the dollar sign in his book. Katz and Lindell tend to just say "Choose". Boneh uses$R$instead of dollar and specifies uniformity. I dislike the dollar sign for TeX reasons, but it is widespread. Sep 16 at 6:40 • I checked standard references and you are right, my usage is kinda marginal. Plus I discovered the hard way that \$ causes trouble in the rendering. So in the end I propose$$\begin{eqnarray*} \mathrm{Gen}:&&k\gets\{0,\ldots,25\}^t\\ \mathrm{Enc}:&&c_i=p_i+k_{i\bmod t}\bmod{26}\\ \mathrm{Dec}:&&p_i=c_i-k_{i\bmod t}\bmod{26} \end{eqnarray*}$$ with \bmodrather than \pmod, because only the former is an operator, and insures the outcome is in $[0,t)$ or $[0,26)$.