Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Reaped: Cryptogram Solver

by NodeReaper (Curate)
on Mar 23, 2001 at 04:37 UTC ( [id://66525]=perlquestion: print w/replies, xml ) Need Help??

NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

This node was taken out by the NodeReaper on May 26, 2021 at 21:47 UTC

You may view the original node and the consideration vote tally.

Replies are listed 'Best First'.
Re: Cryptogram Solver
by chipmunk (Parson) on Mar 23, 2001 at 09:45 UTC
    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; }
Re: Cryptogram Solver
by rpc (Monk) on Mar 23, 2001 at 05:37 UTC
    This is basically a two step problem.

    1. Generate a unique combination of symbols. Don't repeat the same combination twice.
    2. Decide whether or not the substitution generates meaningful output. This can either be done by manual inspection, or frequency analysis. If you choose to use frequency analysis, you'll need a decent set of frequencies to compare it against.

    As far as your existing code is concerned, it might help if you put it in <CODE> tags.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://66525]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found