Some things I noticed when reading through your code...

Both your encryption and your decryption dictionaries have duplicate entries. Of course, only one of these (the last) will be used as the key in the hash. After seeing a couple, I wrote a script to find all duplicates. This is the output:

Plain words with multiple translations: EXCEPT: NEH-DIH, NA-WOL-NE HIGH: WO-TAH, EXPLOSIVE SUPPLY: NAL-YEH-HI, SHIP TANK: CHAY-DA-GAHI, DESTROYER Code words with multiple translations: AH-DEEL-TAHI: DEMOLITION, DETONATOR ALI-KHI-HO-NE-OHA: ELEVATE, TERRACE ALTH-AH-A-TEH: CLASS, TYPE BIH-TSE-DIH: BEFORE, PREVIOUS BILH: CONSIST, WITH BOSH-KEESH: SHORT, SIDE CHA-GEE: THE, THEY CLO-DIH: FIELD, OUT IL-DAY: ARRIVE, REACH KUT: NOW, PRESENT, READY NAHL-KIHD: CALIBER, DEGREE NAZ-PAS: ROUND, SURROUND NEH-DIH: BUT, EXCEPT SHIL-LOH: EXPEDITE, IMMEDIATELY, QUICK SHIP: MERCHANT, SUPPLY TA-A-TAH: ALL, ENTIRE TAH-BAHN: BEACH, SHORE WHO-NEH: REPORT, REVEAL WO-CHI: FLARE, ILLUMINATE

You can use Carp's croak (and carp) instead of die (and warn) to help the user of your module to find where things went awry in his code.

tr works with character ranges, not regular expressions.

Why use indexes in your foreach loops? You can use (implicit) aliases for the current element, leading to clearer and less cluttered code, eg this chunk from your encrypt sub:

my @words = split /\s+/, $str; foreach my $word (@words) { $word = $CDICT{$word}, next if exists $CDICT{$word}; my @letters = split //, $word; foreach (@letters) { next if /\d/; if (exists $CALPHA{$_}) { $_ = $CALPHA{$_}->[ rand @{$CALPHA{$_}} ]; } else { croak "Letter '$_' not found in encryption dictionary"; } } $word = join ' ' => @letters; } return join ' ' => @words;

— Arien


In reply to Re: Crypt::Navajo by Arien
in thread Crypt::Navajo by Cybercosis

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.