Bacon cipher: Difference between revisions

Content added Content deleted
(Added Quackery.)
(→‎Raku: .. use bound sub-array instead of addressing list of 1-char lists .[0] hack; and minor changes)
Line 2,310: Line 2,310:


sub bacon ($s, $msg) {
sub bacon ($s, $msg) {
my $raw = ( [$_] for $s.lc.comb );
my @raw = $s.lc.comb;
my $txt = $raw.grep(*.[0] (elem) @abc);
my @txt := @raw[ (^@raw).grep({@raw[$_] (elem) @abc}) ];
for $msg.lc.comb Z $txt.batch(5) -> ($c-msg, @a) {
for $msg.lc.comb Z @txt.batch(5) -> ($c-msg, @a) {
for @a.kv -> $i, $c-str {
for @a.kv -> $i, $c-str {
my $x := @a[$i][0];
(my $x := @a[$i]) = $x.uc if %bacon{$c-msg}.comb[$i].Int.Bool;
$x = $x.uc if %bacon{$c-msg}.comb[$i].Int.Bool;
} }
} }
$raw.map(*.[0]).join;
@raw.join;
}
}