diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-05-02 04:07:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-02 04:07:18 +0100 |
| commit | a2b36921818173701d96a96c35ee96fbf96b7d42 (patch) | |
| tree | 438733b5ec0e401d9cf462b6b3995d7876c550bc | |
| parent | 5734034277d0c817d3c6efd4f97c18501a3215f5 (diff) | |
| parent | 9352a973af9d30064898c6933fd6190bdb670590 (diff) | |
| download | perlweeklychallenge-club-a2b36921818173701d96a96c35ee96fbf96b7d42.tar.gz perlweeklychallenge-club-a2b36921818173701d96a96c35ee96fbf96b7d42.tar.bz2 perlweeklychallenge-club-a2b36921818173701d96a96c35ee96fbf96b7d42.zip | |
Merge pull request #6039 from Hiranyaloka/ch-162
fix double letter handling
| -rwxr-xr-x | challenge-162/rick-bychowski/raku/ch-2.raku | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/challenge-162/rick-bychowski/raku/ch-2.raku b/challenge-162/rick-bychowski/raku/ch-2.raku index 24b9948f95..ba28b3a509 100755 --- a/challenge-162/rick-bychowski/raku/ch-2.raku +++ b/challenge-162/rick-bychowski/raku/ch-2.raku @@ -5,7 +5,7 @@ sub MAIN( Str $cmd where {$cmd ~~ /^'encrypt'|'decrypt'$/} = 'encrypt', Str :$key = 'Playfair Example', # can contain non-alpha chars - Str :$secret = 'Meet me at the Whisky a Go Go', # the text to encrypt or decrypt + Str :$secret = 'Hide the gold in the tree stump', # the text to encrypt or decrypt Str :$ij where {$ij.chars > 1} = 'ij', # the two redundant chars, keep first Str :$xq where {$xq.chars > 1} = 'xq' # padding for double letter or odd secret ) { @@ -19,14 +19,14 @@ sub MAIN( loop ( my $n=0; $n < 5; $n++ ){ %matrix{"@matrix[$m][$n]"} = [$m,$n]; } - } + } my @result; my $plaintext = $secret.lc.subst(/<-[a .. z]>/,'', :g).subst(/$j/,$i, :g); $plaintext = $plaintext.chars % 2 == 1 ?? $plaintext ~ $xq.comb.[0] !! $plaintext; for $plaintext.comb -> $a, $beta { my $b = $beta; # make copy in case it needs to be substituted $b = $a eq $beta ?? $xq.comb.[0] !! $beta; # try subs to 'x' - $b = $a eq $b ?? $xq.comb.[1] !! $beta; # 'x' fails, subs to 'q' + $b = $a eq $b ?? $xq.comb.[1] !! $b; # 'x' fails, subs to 'q' my $am = %matrix{$a}[0]; my $an = %matrix{$a}[1]; my $bm = %matrix{$b}[0]; |
