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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Golf) Cryptographer's Tool #2
by chipmunk (Parson) on Jun 26, 2001 at 01:38 UTC | |
|
Re: (Golf) Cryptographer's Tool #2
by petral (Curate) on Jun 26, 2001 at 02:02 UTC | |
by tadman (Prior) on Jun 27, 2001 at 03:27 UTC | |
by chipmunk (Parson) on Jun 27, 2001 at 06:12 UTC |