# Find the key to a Vigenère cipher, given known ciphertext and plaintext

I have the ciphertext and the plaintext. Is it possible to know the key? If not, what do I need to find it?

-

Yes.

Remember that, in a Vigenère cipher, the $n$-th ciphertext letter is calculated by adding the $n$-th plaintext letter and the $n$-th key letter (where the key is repeated as many times as necessary to make it as long as the plaintext) modulo 26 (for the standard English alphabet), i.e.:

$$c_n \equiv p_n + k_n \mod 26 \tag1$$

(Here, I'll assume the usual conversion between letters of the alphabet and numbers modulo 26, i.e. $\rm A = 0$, $\rm B = 1$, $\rm C = 2$, $\dotsc$, $\rm Z = 25$.)

Conversely, to decrypt the message, the key is subtracted from the plaintext: $$p_n \equiv c_n - k_n \mod 26 \tag2$$

Note that the decryption rule $(2)$ is obtained from the encryption rule $(1)$ by simple algebraic manipulation: we merely need to subtract $k_n$ from both sides of the equation. Conversely, if we know $p_n$ and $c_n$, we can solve for $k_n$ simply by subtracting $p_n$ from both sides of $(1)$:

$$k_n = c_n - p_n \mod 26 \tag3$$

Note that similarity to the decryption rule $(2)$. Basically, to find out the key, given the ciphertext and plaintext, you simply need to decrypt the ciphertext using the plaintext as the key.

-
Got it, thanks a lot!! –  Jose Dec 7 '13 at 20:30