Caesar ciphers
A Caesar cipher with shift=N is the process of replacing any alphabetic character in a string with the letter which is N positions ahead in the alphabet (wrapping back at the beginning).
This is the key for Caesar(shift=5) (supposing a single-case English alphabet):
these: ABCDEFGHIJKLMNOPQRSTUVWXYZ
map to: FGHIJKLMNOPQRSTUVWXYZABCDE
And this is the result of applying it to "HELLO, WORLD!":
"HELLO, WORLD!"
"MJQQT, BTWQI!"
There have been other challenges (like these) requiring to crack the Caesar cipher, using an extra piece of information beyond the ciphertext to mathematically figure out the shift.
This challenge
This challenge gives you no extra hint. It just asks to:
«Write a program or function that takes a short Caesar-encrypted text and finds with high probability the original plain English text.»
To avoid any doubts, I'm asking you to try to crack patterns in the English language (like for instance the high probability that the most abundant letter decodes to an "e").
Your function/program takes as input:
- a string of characters from this ascii subset: "
abcdefghijklmnopqrstuvwxyz()-,;:"'!?
", containing 5 to 10 words (i.e. bits separated by "
It should output with high accuracy:
- the shift N (in the range 0..25) that was most likely used to obtain this string from a unencrypted sentence made of English words
- OR the anti-shift M (in the range 0..25) that would be required to obtain an unencrypted sentence made of English words (M = 26 - N except for N = 0, for which M = 0 too)
- OR the unencrypted sentence itself
- (OR just the alphabetic characters of it)
Scoring
This is both code-golf and test-battery, so you need to write a short code (low #bytes) that performs sufficiently well (high #correct answ.) on a large number of test cases.
The score is computed as (these are equivalent):
$${\rm score} = \frac{{\rm \#bytes}}{\rm accuracy} = \frac{10000\cdot {{\rm \#bytes}}}{\rm \# correct\,\,answ.} = \frac{{\rm \#bytes}}{1-\frac{\rm \# errors}{10000}}$$
after having tested the code on a sample of 10'000 cyphertexts. Lowest score (per programming language) wins.
Accuracy must be at least 30% for a qualifying answer.
The 10'000 test cases are here. Here is an excerpt:
jubx rmnwcroh ngrbcrwp kruub cqjc fn 9 17 also identify existing bills that we
always have it compute all the posterior possibilities for all 0 0 always have it compute all the posterior possibilities for all
fuhgleoh vrxufhv djuhh wkdw vxssob zloo eh yhub wljkw wkurxjkrxw 3 23 credible sources agree that supply will be very tight throughout
zhuh qrw vhqvlwlyh wr wkh 3 23 were not sensitive to the
wivv, jf zk'j rmrzcrscv kf repfev ivxriucvjj fw vtfefdzt jkrklj 17 9 free, so it's available to anyone regardless of economic status
svvecdbkdsyx yp ryg dbisxq dy cryo-rybx sx k 10 16 illustration of how trying to shoe-horn in a
ivhlzivu kf gifultv, reu sp 17 9 required to produce, and by
svwev nwz, eqbp bpm illml 8 18 known for, with the added
Use the first column as a sequence of inputs with which to test your program/function.
Aim at predicting correctly the output. The correct output is reported in the second, third and fourth columns in different valid formats. Be consistent with your output: always aim at outputting the shift, or the anti-shift (remember, this is 26-N modulo 26), or the plaintext.
(Notes: (1) the battery file is made of fixed-length columns, it's not separator-based; a CSV version is provided here that uses double quotes when necessary, and escapes double quotes with double-double quotes (""
); (2) the battery file is based on a corpus and may contain offensive words)
If your code has a very slow runtime, or for the purpose of showing proof of your score on services like AttemptThisOnline, you can use just a subset of the test battery as long as you pick from the head
and not cherry pick. If possible, try to run the code locally on the whole battery or the largest head-subset you can handle, before declaring your score.
etoainsr
works in 9657 of the tests \$\endgroup\$e
is enough to hit ~35%. \$\endgroup\$