3
$\begingroup$

So I found this question in a model paper,

Break ciphertext ”BJJY GPXF DI TJPM ZSYH” which is encrypted by a Caesar Cipher.

This gives a meaningful plaintext if we use 21 as the shift key. So the answer is

"GOOD LUCK IN YOUR EXAM"

Do we have to find the shift key by guessing all the possible keys until we find the correct one, or is there any other way to find it?

$\endgroup$
2
  • 2
    $\begingroup$ Also see this Q&A on Puzzling.SE $\endgroup$
    – SEJPM
    Commented Jun 17, 2017 at 12:29
  • $\begingroup$ Do you mean is there a faster method than brute-forcing? $\endgroup$
    – Legorooj
    Commented Dec 4, 2019 at 1:57

2 Answers 2

7
$\begingroup$

There are only 26 possible shifts with the Caesar cipher, so you can check them all pretty quickly with a computer, or by hand for fun.

You could also get one step more sophisticated and do a frequency analysis: make histograms of ciphertext letters and compare those to the frequencies of English (e is the most common single letter; followed by t, a...just remember Etaoin Shrdlu and you'll be fine). Then you can do a $\chi$-squared test to compare your ciphertext frequencies to the expected ones from English.


Usual warning: because of how easy this is to break, make sure you only use it for fun: it offers no real security. Here's a longer discussion about cracking ciphers by hand.

$\endgroup$
1
  • $\begingroup$ @yeshikSenadeera If you can crack a cipher by hand, don't trust it's security. Anything you can do in 15 minutes a CPU/GPU program can do in a second or less. Though I'd point out that you might spend longer writing the code to brute-force than it'd take you to crack by hand. $\endgroup$
    – Legorooj
    Commented Dec 4, 2019 at 2:00
2
$\begingroup$

As galvatron notes, there are only 26 possible keys, so you can just try them all even if you're working by hand. (If you have a computer, it's trivial.) Note that you don't need to decrypt the entire ciphertext with each key; just decrypting, say, the first word should be enough to rule out most if not all wrong keys.

In this particular case, since your ciphertext has word breaks, you can also exploit the fact that all normal English words contain at least one vowel (including Y). So, in particular, you can pretty safely assume that one of the two letters in the ciphertext word DI must decrypt to a vowel, which limits the possible keys to just 2 × 6 = 12 (including the null key that encrypts I to I, which we may immediately rule out). In fact, only one of these keys yields a common English word (IN), and indeed turns out to be the correct one.

(Of course, in general, you might be unlucky and the "word" you picked might turn out to be an acronym with no vowels at all. If so, you'll notice it when none of the decryptions makes any sense, at which point you can go back and try the other keys you previously ruled out as unlikely.)


As galvatron also notes, a good general method for breaking simple substitution ciphers is frequency analysis. Basically, you start by counting the number of times each letter occurs in the ciphertext, and then assume that the most common letters in the ciphertext most likely correspond to the most common letters in plain English text.

Unfortunately, for your specific example ciphertext, frequency analysis is somewhat less effective than usual. Not only is the ciphertext too short to yield reliable frequency data (most letters in it occur only once), but it looks as if the plaintext might even have been deliberately chosen to have an untypical frequency distribution. Of the three most common English letters, T is completely absent from the plaintext, and E and A both occurs only once, in the word EXAM, which also contains an X (one of the rarest letters in English, after Q and Z).

That said, if you persist with frequency analysis, trying to match the most common ciphertext letter (J, occurring 3 times) to the most common English letters (which can be easily memorized as the nonsense phrase ETAOIN SHRDLU), you're likely to hit the correct match (J = O) after only three false starts. If the author of the question had really wanted to mess up frequency analysis, they'd have replaced the word GOOD with MUCH. ;)

$\endgroup$

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.