This is part 2 of a 3 part series (part 1 is given here). You may want to refer to part 1 for some ideas to help here; in addition, part 2's answer will help with part 3 which will not be posted for a few more days.

Some definitions now: ciphertext will be the text that makes up the encoded message, while normaltext will be the decoded message. All characters from both cypher and normal text outside of punctuation will be within the same alphabet, represented by the text string $alphabet; all characters in this alphabet are in the ASCII 7-bit standard set, but may not strictly be a-z, for example. There are no capital letters in either ciphertext or normaltext; that is, if 'a' and 'A' are both used in the same message, they represent two completely different letters as opposed to the normal way of considering them as two different cases of the same letter. A cipher-pattern is what was previously described in part 1; eg, a possible cipher-pattern for the word 'people' is 'abcadb'. Also, for purposes of this, assume the only punctuation is the space (' '); all other punctuation has been stripped or is otherwise part of the alphabet.

Given: a ciphertext phrase as a string, the alphabet string that was used in both normal and cyphertext, and a dictionary that is also in that alphabet as an array (assume this has been previously loaded by a call such as @dict = <DICT>; where DICT is a filehandle to /usr/dict/words or such). Also, two numbers $min and $max, where 0 < $min < $max.

Find a perl golf solution that returns a hash of arrays; the keys of this hash are the cyphertext words from the phrase, containing at least $min characters but no more than $max characters. The values are arrays of words from the dictionary that have the same cipher-pattern as the associated hash key.

The solution should count the number of characters between the brackets of the subroutine described above; if you use another subroutine, such as the one from part 1, you need to include the minimum 7 characters for a sub ("sub x{}") in your character count as well as the text of that sub.

As examples of how the sub should be used, I give the following:

my $alphabet = join '', ('a'..'z'); my $phrase = "abcd efgdhij kijl hecmin"; my ( $min, $max ) = (5, 15); my @dict = <DICT>; # or similar my %hash = t( $phrase, $alphabet, $min, $max, \@dict ); # see update 2 below!! # Hash will look like: # %hash = ( efgdhij => [ "another", "fathers", ... ], # hecmin => [ "hacker", "strong", ... ] );

(Note that this one should be rather simple despite the length of the setup for it...)

update fixed links, qualified "punctuation" a bit

update 2: On second thought, it's probably saner to pass the dictionary array as a reference rather than value. I'll note that in what I expect to be the average solution, this only adds an extra character for the one dereferencing that you have to do in the subroutine.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

In reply to (Golf) Cryptographer's Tool #2 by Masem

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.