This looks very interesting. The only time I've ever come across these ciphers is as part of a crossword; a typical example would be where the solutions to some half a dozen marked clues need to be enciphered before entry into the grid, using some keyword to be determined (by looking at the checking letters, and spotting a connection with thematic elements).

Of course, when solving such puzzles this program would be of limited use - the majority of the effort goes into finding the keyword. It might be interesting to attempt a solver, that given some (possibly partial) pairs of plain and enciphered words would attempt to find possible keywords. Since there are many possibilities even when the encipherments are fully known (since the cipher square can be rotated horizontally and vertically without changing the cipher), the aim would be to minimize the length of the keyword by shifting the longest possible set of ordered letters to the end.

It always surprises me how little information is required to crack a Playfair cipher; just for fun, here's what was provided in a recent crossword once you'd solved all the clues:

HANDEL => SL??HO LEHRER => OH??KN MOZART => NL??MZ CHOPIN => LK??DR
with the additional information that the "odd man out" is "the source of the theme".

One minor point: when used for this purpose, the program's habit of grouping letters by fives is a bit irritating; it'd be more convenient in this case for it instead to preserve the whitespace of the original text. Then you could supply "Handel Lehrer Mozart Chopin" as input and get back the ciphertext in the form "xxxxxx xxxxxx xxxxxx xxxxxx". Losing the handling of odd letters and repeats, simplifying to this main loop would achieve that:

while (<>) { while (/\G(\W*)(\w)(\W*)(\w)(\W*)/gc) { my($out2, $out4) = transcribe($2, $4); print $1, $out2, $3, $out4, $5; } print $1 if /\G(.*\n?)$/gc; }

Hugo

In reply to Re: Dubious Cryptography: Playfair Cipher à la Sayers by hv
in thread Dubious Cryptography: Playfair Cipher à la Sayers by ChemBoy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.