aboutsummaryrefslogtreecommitdiff
path: root/challenge-025/stuart-little/raku/ch-2.p6
blob: 969223a0fb6a9693581b479b20392f749b1aeb1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env perl6
use v6;

use HTTP::Tiny;
use JSON::Fast;

my %*SUB-MAIN-OPTS=:named-anywhere,;
sub MAIN(
    Str $text is copy,
    Str :a1(:$alphabet1) = 'XLEMFHIWOVNYRUDQCJPASGBTKZ',
    Str :a2(:$alphabet2) = 'SGLBIZHJMFTRXAVKNQPDWYCUOE',
    Bool :e(:$encode),
    Bool :d(:$decode),
) {
    my $URL=qq{https://www.dcode.fr/api/};
    my %data=(
	tool => 'chao-cipher',	
	alphabet1 => $alphabet1,
	alphabet2 => $alphabet2,
    );

    $text ~~ s:g/\s+/+/;
    ($decode) ?? (%data.<ciphertext> = $text) !! (%data.<plaintext> = $text);

    say .<content>.decode.&from-json.<results> with HTTP::Tiny.new(agent => 'HTTP-Tiny').post: $URL, content => %data;
}