aboutsummaryrefslogtreecommitdiff
path: root/challenge-162
diff options
context:
space:
mode:
authorRick Bychowski <rick@hiranyaloka.com>2022-05-01 19:03:39 -0700
committerRick Bychowski <rick@hiranyaloka.com>2022-05-01 19:03:39 -0700
commit9352a973af9d30064898c6933fd6190bdb670590 (patch)
tree48bb3bf456d9d14af59d62171f4fcba8aa9b928c /challenge-162
parent8920b32abbf19d0f08e41992b01dcb9e7670d484 (diff)
downloadperlweeklychallenge-club-9352a973af9d30064898c6933fd6190bdb670590.tar.gz
perlweeklychallenge-club-9352a973af9d30064898c6933fd6190bdb670590.tar.bz2
perlweeklychallenge-club-9352a973af9d30064898c6933fd6190bdb670590.zip
fix double letter handling
Diffstat (limited to 'challenge-162')
-rwxr-xr-xchallenge-162/rick-bychowski/raku/ch-2.raku6
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];