blob: ca65f7caa893bdfa0adbb924514ff45048db30c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#!/usr/bin/env perl6
# ch-1.p6 - Square code
#
# Ryan Thompson <rjt@cpan.org>
sub MAIN( Str $plaintext = 'The quick brown fox jumps over the lazy dog' ) {
say encode($plaintext, 8);
}
#| Encode plaintext according to the Square Secret Code definition
# $width is by default chosen to give a "square" result
sub encode( Str $plain, Int $width = $plain.chars.sqrt.Int ) {
my @s;
$plain.lc.subst(/\s/,'',:g).comb.kv.map: { @s[$^i % $width] ~= $^str };
@s.join(' ')
}
|