NAME

Games::Cryptoquote - Solves Cryptoquotes

SYNOPSIS

 use Games::Cryptoquote;

 my $quote     = 
 'Omyreeohrmy jsvlrtd stpimf yjr hepnr ztpvesox yjsy yjod ztphtsx od brtu vppe!';
 my $author    = q(Npn P'Mroee);

 my $c = Games::Cryptoquote->new();

 unless (-e 'patterns.txt')
 {
     $c->write_patterns(
         dict_file => '/usr/share/dict/words',
         pattern_file => 'patterns.txt'
     ) or die;
 }
 $c->build_dictionary(file => 'patterns.txt', type => 'patterns') or die;
 
 $c->quote($quote);
 $c->source($author);
 $c->timeout(10);

 my $time1     = time;
 $c->solve();
 my $time2     = time;
 
 print  "Solution : ".$c->get_solution('quote')." -- ".
                      $c->get_solution('source')."\n";
 printf "Took     : %f seconds\n", $time2 - $time1;

DESCRIPTION

This module solves cryptoquote puzzles, where each letter stands for
a different letter.  These puzzles are typically found in newspapers
with comics and crossword puzzles.  You can also find several
examples on the internet, which are nice, because you can cut and paste
into your script for expeditious solving.

Note that you'll get some pretty interesting results if
your cryptoquote puzzle does not yield a unique result,
or if it uses words that are not in your dictionary.

Public Methods:

new (constructor)

takes no arguments.

quote

get/set quote.

source

get/set source (where the quote came from -- author, etc.).

timeout

get/set timeout (number of seconds before giving up).

build_dictionary

Build a huge hash, using either a dictionary like /usr/share/dict/words
or a specially-formatted patterns file, which takes a lot less time to
process.

write_patterns

Read in a dictionary file, like /usr/share/dict/words, and write out
a specially-formatted patterns file, which takes a lot less time to
process.

solve

Do the dirty work.  Assign solution variables for later access via
the solution() method.

solution

Obtain the solution for either the quote or the source.  Specify which
one you want with an argument of "quote" or "source".

See the README for the introduction.

BUGS

Things seem to be coming out in lower-case.  Weird.
Doesn't support contractions (like "Doesn't").
Assumes no words will contain "|" character.

TODO

Lots of general cleanup, mostly bad OO style Adam is chastizing me for.
Add clearer documentation.
Add support for contractions.
Add more tests.
Fix bugs.
Enhance interface.
Optimize algorithm.
Fix typos that I haven't bothered to look for.

CREDITS

Thanks to Darren Key <emdeeki@yahoo.com> for helping launch this idea.
Thanks to Peter Kioko <peterkioko@hotmail.com> for the optimized
  mind-bending algorithm.
Thanks to Adam Foxson <afoxson@pobox.com> for making this CPANable
  and for numerous other cleanups.

AUTHOR

Bob O'Neill, <bobo@cpan.org>

SEE ALSO

perl.