in reply to Re: Playfair cipher
in thread Playfair cipher

my $message = uc(<>); $message =~ s/[^A-Z0-9]//gi; # remove punct, etc $message =~ s/j/i/gi; $message =~ s/q/O/gi; # replace [Qq] with [Oo] $message =~ s/\s+//g; # remove spaces
my $message = uc <>; $message =~ tr/A-Z0-9//cd; # remove punct, etc $message =~ tr/JQ/IO/;


Update:

my @range = ("Q","V","X","Y","Z",); ... my $i = int(rand(4)); my $letter = $range[$i];

Your @range array contains five elements but you are only accessing the first four of them.

That is usually written as:

my @range = ("Q","V","X","Y","Z",); ... my $letter = $range[ rand @range ];

Replies are listed 'Best First'.
Re^3: Playfair cipher
by ww (Archbishop) on Jun 23, 2011 at 02:25 UTC

    Right on all counts!

    TY and ++

    Coder (yeah, /me) abandoned all good practice by writing a little code; getting another (allegedly) bright idea; cutting/tweaking/adding functions/routines/code without careful review of previous code (and then 'rinsing, repeating').

    The initial idea may or may not be worth anything; the procedures by which this code was written deserve to be castigated far more harshly than the gentle jwkrahn did. But, gentle reader, future development should attend carefully to those wise observations.