How can I find the Caesar cipher key if I have an encrypted message and part of the decrypted message? For example: I know that the message ends with a constant set of words, but the length of the key is not known.

I have tried using the Kasiski test to check for repeating strings in the encrypted message, but the message i have is a very small one (around 200 characters) so i don't see any useful patterns that might help me narrow down on the length on the key.

  • 2
    $\begingroup$ What do you mean with "the length of the key is not known"? The Caesar cipher always has a key length of 1 character (or rather, one number relative to the size of the alphabet – from 0 to 25), at least in the classical implementation. $\endgroup$
    – Maarten Bodewes
    Commented Oct 30, 2016 at 9:09
  • $\begingroup$ My bad, what i have is a vigenere's cipher. Since it was doing the same function as a caesar cipher i got confused between the two. Thanks for pointing it ou. $\endgroup$
    – Kira
    Commented Oct 30, 2016 at 20:51
  • $\begingroup$ For your information: I have rolled back your edit because changing the question from “Caesar” to “Vigenere” completely changes what is being asked, and would void the already posted answer, votes, and comments. If you want to ask a similar question about Vigenere, simply ask a new question. $\endgroup$
    – e-sushi
    Commented Oct 30, 2016 at 20:58

1 Answer 1


For the Caesar cipher there are only 25 possible keys (and the key $k=0$ which degenerates into the identity function, ciphertext = plaintext).

Just try all possible shifts one by one starting from $k=1$ to $k=25$ (this constitutes a brute force attack). After each shift you need to validate that it results in an intelligible plain text by decryption of the ciphertext. For the Caesar cipher brute force attack is efficient.

Now if you have plaintext and corresponding ciphertext pair work become more easy you don't need to do brute force attack. As in generic Caesar cipher encryption/decryption is defined as

$$C = (P + K) \bmod 26$$

$$P = (C - K) \bmod 26$$

Then from above $K = C - P$ (for each corresponding ciphertext / plaintext character).

For example if the plaintext is "abc" and the ciphertext is "def". Then teh 'd' zero-based index is $3$ within the alphabet. And the and 'a' location is $0$ then $K=3-0=3$

  • $\begingroup$ Please reread your answer before posting. It said: "In Caesar cipher there are only 25 possible ciphertext", which is of course nonsense. You can hit "edit" to see the formatting tricks that I used to better format your answer. $\endgroup$
    – Maarten Bodewes
    Commented Oct 30, 2016 at 10:26
  • $\begingroup$ @MaartenBodewes if there are only 25 keys possible then this means there are can be 25 possible ciphertext corresponding to plaintext. Does not it make sense? $\endgroup$
    – Infinity
    Commented Oct 30, 2016 at 12:19
  • 2
    $\begingroup$ Yes, that does make sense, for one specific plaintext. But that last bit of vital information was missing. Furthermore, brute force depends on the amount of possible keys, not the amount of possible ciphertext. $\endgroup$
    – Maarten Bodewes
    Commented Oct 30, 2016 at 12:28
  • $\begingroup$ I would change 26 for SIZE_OF_ALPHABET. But is of course understandable :-) $\endgroup$
    – eightShirt
    Commented Nov 1, 2016 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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