4
$\begingroup$

The 'message' below is a substitution cipher.

It is a fun challenge to write a computer program to read in the file and count up the letters and then use expected letter frequencies to translate the code. It is a slightly harder challenge to write a computer program that will translate it on the basis of a translation table you give it in a file, e.g.

a->q
b->z
c->k
....
etc.

It can be solved by hand, but that will take more time and effort.

Now I know that there are some websites that will translate this message for you with no problem, but I thought it might be fun to pose this as a question for anyone who wants the programming challenge or wants to solve it by hand.

There are between 4000 and 5000 characters so there are enough to get a good frequency distribution of the letters.

When you solve it you will see why I chose this particular 'message' to encrypt...

So in summary, I set this puzzle hoping it will be a fun challenge.

So here is the 'message'

tdoufqntdufjegvofjfjenfgdqfebyueqfueqqxoubrrhjerelfjevbhoufdfjelybvoukyddgvofjfjeyegbycfjbffjepnqoueqqvbqudvdnfdxdnyjbulqbulfjbfvegnqfvjorebvbhfjefogebqpeqfvegokjfnuforvemdnrlqeevjbfvbqouqfdyexdynqfjeldmfdyjblletbyfelfdjoqtbfoeufqbuldurhfjeouqtemfdybulghqerxyegbouelofjoucfjbfombujerthdnfdtbqqbujdnyoubuoufeyeqfoukbultydxofbpregbuueyqboljdrgeqlybvoukjoqmjboyntfdfjefbprebulqtyebloukdnfouxydufdxjogfjesbyodnqtbteyqntduvjomjveyeyemdylelfjebufomqdxfjelbumoukgeubqfdhdnxyoeulvbfqduodvehdneseyhbfduegeufxdyjbsoukbrrdvelhdnyubfnybrmnyodqofhfdyegbouqdrduknuqbfoqxoelfdhdnouqtemfdyfjevjdreoumoleufgbhbttebrbqbyegbycbpretydxeqqodubrqfnlhognqfferrhdnxoyqfdxbrrfjeoufeyeqfoukmoymngqfbumeqmduuemfelvofjfjetyesodnqmduqnrfbfoduqvjomjgyjorfdumnpoffjbqjblvofjgeoupbceyqfyeefjefjeuqjdyfrhyembtofnrbfelfjexbmfqvjomjjbsebryeblhpeeuyemdylelojbsejeyeouxydufdxgefjeqeqouknrbytydlnmfoduqbfvjomjduegokjfqgorejblfjehudftydselfjegqerseqfdpefjexdyeynuueyqdxqdfeyyoprebfybkelhobgxboyrhxbgorobyvofjbrrxdygqdxqemyefvyofoukqbulbgghqerxfjebnfjdydxbfyoxroukgdudkybtjntdufjeqnpwemfouvjomjobubrhieduejnulyelbulqoafhqetbybfemotjeyqpnfomduxeqqfjbffjoqoqeufoyerhuevfdgefjedpwemfdxfjdqevjdouseufelfjeqhqfegjbqbttbyeufrhpeeufdmdumebrfjbffjeqemjbybmfeyqmdusehbgeqqbkebulfdkosefjeolebfjbffjehbyefjegeyeybuldgqcefmjeqdxmjorlyeujbsoukdumeyemdkuoieljdveseyfjbffjeqhgpdrqqfddlxdyreffeyqbuljbsoukbttroelfjeynreqvjomjknolenqoubrrxdygqdxqemyefvyofoukqfjeqdrnfoduvbqebqheudnkjfjexoyqfgeqqbkeqnpgoffelfdgevbqqdqjdyffjbfofvbqogtdqqoprexdygefdldgdyefjbufdqbhvofjqdgemduxoleumefjbffjeqhgpdraaaqfddlxdyebqhdnbyebvbyeeoqfjegdqfmdggdureffeyoufjeeukroqjbrtjbpefbuloftyeldgoubfeqfdqdgbycelbueafeuffjbfeseuoubqjdyfqeufeumeduevdnrleatemffdxoulofgdqfdxfeudnfdxxoxfeeuqhgpdrqoufjexoyqfgeqqbkexdnyveyefjeqbgeqdofvbqyebqdubprefdqeffjoqldvubqeofoqfynefjbfouqdgembqeqfjexoknyevbqpebyoukbxrbkbulouqdgembqequdfpnfofvbqtydpbprexydgfjevbhouvjomjfjexrbkqveyeloqfyopnfelfjbffjehveyenqelfdpyebcfjeqeufeumentoufdvdylqobmmetfelfjoqbqbjhtdfjeqoqbuludfelfjbfevbqyetyeqeufelphaaapnfudvmbgefjeyebrloxxomnrfhdxfjeouznoyhfjedyleydxfjeeukroqjreffeyqbxfeyeoqphudgebuqverrgbycelbulbuhtyetduleybumevjomjgbhpeqjdvuoububseybkedxbtyoufelqjeefgbhpeyeseyqeloubqoukreqjdyfqeufeumeqtebcoukydnkjrhfbdouqjylbulrbyefjeungeyombrdyleyouvjomjreffeyqdmmnypnffbdbulobyeseyhuebyrhbpyebqfdxebmjdfjeybulofvdnrlpebueulreqqfbqcfdfyhebmjmdgpoubfodunuforbgebuoukvbqbyyoselbfofjeyexdyevbofelxdyxyeqjgbfeyobroughqemduloufeysoevvofjgyjorfdumnpoffjevbqbprefdkosegefvddfjeyqjdyfqeufeumeqbulduegeqqbkevjomjbttebyelqoumefjeyevbqudxrbkfdpebqoukrevdyljeyebyefjeqhgpdrqudvoufjeqoukrevdylojbsebryeblhkdffjefvdeqmdgoukqemdulbulxdnyfjoubvdyldxxosereffeyqofgokjfpeqeseydyreseydyueseyfjeyembupeudzneqfodufjbffjerbffeybqbyetrhfdbubttebroqxbyfjegdqftydpbprebulfjemoymngqfbumeqtdoufelfdofqpeoukbyetrhvyoffeuphfjerblhbmmetfoukofbqmdyyemfvebyeudvbprefdqbhfjbffjeqhgpdrqqfbulyeqtemfoserhxdyusbulyeseuudvovbqoumduqoleybpreloxxomnrfhpnfbjbtthfjdnkjftnfgeoutdqqeqqodudxqeseybrdfjeyreffeyqofdmmnyyelfdgefjbfoxfjeqebttebrqmbgebqoeatemfelxydgqdgeduevjdjblpeeuoufogbfevofjfjerblhoujeyebyrhroxebmdgpoubfoduvjomjmdufbouelfvdeqvofjfjyeereffeyqpefveeugokjfseyhverrqfbulxdyfjeubgeerqoedueabgoubfoduoxdnulfjbfqnmjbmdgpoubfoduxdygelfjefeygoubfodudxfjegeqqbkevjomjvbqfjyeefogeqyetebfelofvbqmeyfbourhqdgebttebrfderqoeoufjoqvbhojblkdfghrqbulopnfvjbfbttebrmdnrlofpefjeyeveyedurhxdnyreffeyqoufjevdylvjomjtyemelelerqoebulofeuleloueqnyerhfjevdylgnqfpemdgeofyoelbrrdfjeyxdnyreffeyqeuloukouepnfmdnrlxouluduefdxoffjembqeqdudvovbqoutdqqeqqodudxmdbulgbulovbqoubtdqofodufdbffbmcfjexoyqfgeqqbkedumegdyelosoloukofoufdvdylqbultnffoukldfqxdyebmjqhgpdrvjomjvbqqforrnucudvuqdfyebfelofvdyceldnfoufjoqxbqjodugeyeeqrueudvfjexoyqfreffeymbudurhpebvjomjoqbgdqfnqexnrloqmdseyhqoumeofdmmnyqudxeveyfjbufjyeefogeqoufjoqqjdyfqeufeumebulfjejoqbrqdbttbyeufoufjeqemdulvdyludvofpemdgeqbgjeyebeqrbuedyxorroukoufjedpsodnqsbmbumoeqoufjeubgebgjeyebpeqrbuehojblqdgbuhreffeyqudvfjbfomdnrltydmeelvofjmduqoleybpremduxoleumefdfjeqemdulgeqqbkevjomjvdyceldnfoufjoqxbqjoduberyoeqjeyeomdnrldurhgbceqeuqephtnffoukfbulkxdyfjegoqqoukreffeyqbulqnttdqoukfjbffjeubgevbqfjbfdxqdgejdnqedyouubfvjomjfjevyofeyvbqqfbhoukouqtemfdygbyfoubulojblroqfeuelvofjfjenfgdqfoufeyeqffdfjexnrrbulmrebybmmdnufdxjdvghxyoeuljbltydlnmelyeqnrfqvjomjjblrelfdqdmdgtrefebmdggbuldseydnyloxxomnrfoeqvjbflolhdnldfjeuqoybqcelfjeouqtemfdyojbleseyhyebqdufdqnttdqefjbffjoqbpeqrbuehvbqbubgeyombuqoumebpeoqbubgeyombumdufybmfodubulqoumebreffeyxydgbgeyombjblpeeufjeqfbyfouktdoufdxbrrfjefydnpreojblbrqdeseyhmbnqefdfjoucfjbffjeyevbqqdgemyogoubrqemyefoufjegbffeyfjerblhqbrrnqoduqfdjeytbqfbuljeyyexnqbrfdfbcejeyjnqpbuloufdjeymduxoleume

$\endgroup$
  • $\begingroup$ It amazes me how those sites can make such a challenge elementary. $\endgroup$ – noedne May 30 '18 at 19:46
  • $\begingroup$ Are we aloud to use computers? $\endgroup$ – QuantumTwinkie May 30 '18 at 19:50
  • 1
    $\begingroup$ @QuantumTwinkie a programming challenge would be pretty tough without a computer.... so yes you are allowed. .... and, of course, you can use whatever method you want to solve. Sorry if I went on about it too much in the question, the point I wanted to make is that it can be a fun challenge, but I know that websites can be used to solve it with very little effort (or little challenge). $\endgroup$ – tom May 30 '18 at 20:06
  • 2
    $\begingroup$ Like, I found the answer from a website, but I do not want to take the real puzzling from a person who wants to hand solve it. $\endgroup$ – QuantumTwinkie May 30 '18 at 20:10
  • 1
    $\begingroup$ @QuantumTwinkie - thanks for keeping to the spirit of this question. $\endgroup$ – tom May 30 '18 at 21:02
5
$\begingroup$

Here are my tools. Both were whipped up on the spot, but having made both of these exact tools dozens of times in the past, never bothering to actually save them in a file, the Perl bits may have gotten a bit.. bizarre over time. No, not bizarre, maybe.. Convoluted? Condensed? No, "refined"! That is definitely the word I was looking for. :-)

(Not that this is code golf, but since TiO helpfully provides copypasteable SE-compatible syntax for that site..):


Letter frequency analysis: (Bash, 73 bytes)

perl -nle '$a{$_}++for split//}{print "$a{$_}  $_" for keys %a' | sort -n

Try it online!


Translation: (Bash, 33 bytes)

tr a-z XAKOETMYZHGDCUIBSLVPNWJFRQ

Try it online!


The translation has capital letters for plaintext, because you can start with the "identity translation" tr a-z abcdefghijklmnopqrstuvwxyz and then use capital letters for the guesses: it's pretty easy to recognise the patterns the capital letters make in the output.


EDIT: Since the perl above is pretty much write-only code, I decided it was time to reorganise my thought patterns. Here's a much cleaner version of a letter occurrence counter. This version is going to eat more CPU and memory than the original version (because uniq will count only pre-sorted data), but since we aren't dealing with huge data blobs anyway, the added readability more than offsets those drawbacks.

Letter frequency analysis, readable version (Bash, 48 bytes)

perl -pe 's/./$&\n/g' | sort | uniq -c | sort -n

Try it online!

Or if your system has the fold tool from GNU coreutils (seems pretty common):

Letter frequency analysis, prettiest version (Bash, 36 bytes)

fold -w 1 | sort | uniq -c | sort -n

Try it online!

$\endgroup$
  • 1
    $\begingroup$ Bass great job - I am particularly impressed that you can incorporate the computer code that you used in your answer. ... one tiny point though... did you read the translation and see why this 'message' was chosen? .... and by the way your codes are very refined. The bash command for translation is so short! That is frightening. $\endgroup$ – tom May 30 '18 at 22:32
  • 1
    $\begingroup$ @tom, I actually just listened to that audiobook a couple of weeks ago! (Read by Stephen Fry, excellent stuff, that.) The plaintext is very well chosen, as it handily provides several bits of the solution process that I was therefore able to leave out of the answer :-) $\endgroup$ – Bass May 30 '18 at 22:37
  • $\begingroup$ One other thing - I love the transition from lower case to upper case letters as you worked through the translation $\endgroup$ – tom May 30 '18 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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