8
\$\begingroup\$

The Feynman Challenge Cipher #1 is as follows:

MEOTAIHSIBRTEWDGLGKNLANEAINOEEPEYST
NPEUOOEHRONLTIROSDHEOTNPHGAAETOHSZO
TTENTKEPADLYPHEODOWCFORRRNLCUEEEEOP
GMRLHNNDFTOENEALKEHHEATTHNMESCNSHIR
AETDAHLHEMTETRFSWEDOEOENEGFHETAEDGH
RLNNGOAAEOCMTURRSLTDIDOREHNHEHNAYVT
IERHEENECTRNVIOUOEHOTRNWSAYIFSNSHOE
MRTRREUAUUHOHOOHCDCHTEEISEVRLSKLIHI
IAPCHRHSIHPSNWTOIISISHHNWEMTIEYAFEL
NRENLEERYIPHBEROTEVPHNTYATIERTIHEEA
WTWVHTASETHHSDNGEIEAYNHHHNNHTW

The solution is described as:

It is a simple transposition cipher: split the text into 5-column pieces, then read from lower right upward. What results are the opening lines of Chaucer's Canterbury Tales in Middle English.

Which is:

WHANTHATAPRILLEWITHHISSHOURESSOOTET
HEDROGHTEOFMARCHHATHPERCEDTOTHEROOT
EANDBATHEDEVERYVEYNEINSWICHLICOUROF
WHICHVERTUENGENDREDISTHEFLOURWHANZE
PHIRUSEEKWITHHISSWEETEBREFTHINSPIRE
DHATHINEVERYHOLTANDHEETHTHETENDRECR
OPPESANDTHEYONGESONNEHATHINTHERAMHI
SHALVECOURSYRONNEANDSMALEFOWELESMAK
ENMELODYETHATSLEPENALTHENYGHTWITHOP
ENYESOPRIKETHHEMNATUREINHIRCORAGEST
HANNELONGENFOLKTOGOONONPILGRIM

The Challenge:

Write a function to decrypt the cipher.

The output does not need line breaks or spaces.

Input is has no line breaks or spaces.

Shortest solution wins.

(Bonus points if you can solve the other 2 ciphers :P)


My attempt (PHP 77 70):

$b=strrev($a);for($i=0;$i<5;$i++)for($j=0;$j<381;$j++)$r.=$b[$i+$j*5];

http://codepad.org/PFj9tGb1

\$\endgroup\$
1
  • 1
    \$\begingroup\$ What restrictions are there on input assumptions? E.g. both solutions so far assume input as a single line with no whitespace; yours assumes that it's in a variable and gnibbler's assumes that it's on stdin. \$\endgroup\$ Nov 4, 2011 at 9:34

12 Answers 12

7
\$\begingroup\$

Golfscript, 10 chars

n--1%5/zip

Takes input from stdin. It may be separated by newlines, as in the question presentation, or not, as many answers assume. (Stripping the newlines is necessary anyway given that it's likely to arrive with one on the end, which messes up the blocks of 5). If we assume that the input arrives with precisely one newline, being the last character, we can shave one character to

)!(%5/zip
\$\endgroup\$
3
\$\begingroup\$

Mathematica, 51


Mathematica is quite verbose here, but it is also easy to guess what it's doing.

Thread[Characters@#~Partition~5]~Reverse~{1,2}<>""&
\$\endgroup\$
3
\$\begingroup\$

J, 13 characters

|.@(/:5|i.@#)
\$\endgroup\$
2
\$\begingroup\$

Haskell, 52

f s=[s!!(x-i)|x<-[length s],j<-[1..5],i<-[j,j+5..x]]
\$\endgroup\$
1
  • 3
    \$\begingroup\$ x<-[length s]... disgusting. I love it! \$\endgroup\$ Nov 4, 2011 at 20:24
2
\$\begingroup\$

Japt -P, 4 3 bytes

Ôó5

Try it online!

I feel like that was too easy? On a positive note, this can't possibly be golfed too much assuming I am getting the correct result :)

EDIT -1 byte thanks to @Shaggy!

Ôó5    # full program
Ô      # reverse input string
 ó5    # create a 5-element array by repeatedly
       # picking every 5th character.
       # -P flag concatenates array on output!
\$\endgroup\$
1
  • 1
    \$\begingroup\$ There's a shortcut for w ;) \$\endgroup\$
    – Shaggy
    Mar 2, 2019 at 10:36
1
\$\begingroup\$

Python - 56 chars

s=raw_input()
print"".join(s[-1-x::-5]for x in range(5))
\$\endgroup\$
1
  • \$\begingroup\$ 2 characters shorter with python 3 (-4 for input instead of raw_input; +2 for adding parenthesis to print. \$\endgroup\$ Nov 7, 2011 at 17:00
1
\$\begingroup\$

Scala, 62 characters

print((for(x<-0 to 4;y<-379-x to 0 by -5)yield s(y)).mkString)

Making the assumption that the string is already in a variable s as hammar and stevether do.
Taking the input from stdin is a bit uglier (92 chars):

var s=io.Source.stdin.mkString
print((for(x<-0 to 4;y<-379-x to 0 by -5)yield s(y)).mkString)

and it only works if there are no newlines in the input.

\$\endgroup\$
1
\$\begingroup\$

Perl, 58 characters

perl -lne'$c[$c++%5].=$_ for split//}END{$"=$,,print$_=reverse"@c"'
\$\endgroup\$
1
\$\begingroup\$

Scala 63 chars:

(1 to 5).map(n=>s.reverse.drop(n)).map(_.sliding(1,5).mkString)

Assuming the input is in s.

\$\endgroup\$
1
\$\begingroup\$

K, 34

{a::(5*!76)_x;1'{a[;x]@|!#a}@'|!5}
\$\endgroup\$
1
\$\begingroup\$

ECMAScript 6 - 48 Characters

for(c='',i=5;i--;)c+=(x=>s[x]?f(x+5)+s[x]:'')(i)

Assumes that the variable s contains the input string (without any white space characters) and creates the variable c containing the output.

\$\endgroup\$
0
\$\begingroup\$

Python 3.6, 48 bytes

Recursion + f-Strings

f=lambda a:a and f'{a[::-5]+f(a[:-1])}'[:len(a)]

Try it online!

\$\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.