I went to the Code Catacombs to post my script for finding cryptographic matches for a given pattern, and discovered that merlyn had already posted pat. (Some time ago, in fact. :) merlyn's script also has the nice feature of allowing the user to specify literal letters, which appear unchanged in the matching word(s).

By the way, depending on your system, /usr/dict/words may not be very useful at all for solving cryptograms. /usr/dict/words was originally intended for use with the spell utility, which does stemming to guess if a word is spelled correctly. Thus, /usr/dict/words may contain only root words and irregular forms, i.e. talk but not talks, talked, or talking.

I've been working on my own program in Perl to solve cryptograms. I recommend the ENABLE word list.

P.S. Oh, what the heck. My code works somewhat differently from merlyn's, so I'll go ahead and post it here. I expect his use of regexes will be faster than my use of split and hashes, though.

#!/usr/local/bin/perl -w use strict; use Getopt::Std; use vars qw($opt_w); getopts('w:') || die "Bad options.\n"; my $dict = $opt_w || 'wordlist'; open(DICT, $dict) or die "Can't open $dict: $!\n"; my $crypto = shift; my $match = &crypto_canon($crypto); while (<DICT>) { chomp; next if length $match != length $_; next if $match ne &crypto_canon($_); print "$_\n"; } sub crypto_canon { my($word) = @_; my $canon; my %letters; my $next = 'a'; foreach (split //, $word) { if ($_ !~ /[a-z]/) { $canon .= $_; next; } elsif (not exists $letters{$_}) { $letters{$_} = $next++; } $canon .= $letters{$_}; } $canon; }

In reply to Re: Cryptogram Solver by chipmunk
in thread Reaped: Cryptogram Solver by NodeReaper

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.