From da8b19bdb5ac775e6091f8ebf934ed1266503ab7 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 14 Mar 2023 22:35:20 +0100 Subject: Challenge 015 task 2 --- challenge-015/jo-37/perl/ch-2.pl | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 challenge-015/jo-37/perl/ch-2.pl diff --git a/challenge-015/jo-37/perl/ch-2.pl b/challenge-015/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..322f68876a --- /dev/null +++ b/challenge-015/jo-37/perl/ch-2.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0 '!float'; +use PDL; +use experimental 'signatures'; + +our ($tests, $examples, $decrypt, $key); + +run_tests() if $tests || $examples; # does not return + +die <range(0, $t->dim(0), 'p'); + + # Add or substract text and key, take the result mod 26 and convert + # back to characters. + join '', map chr($_ + ord('a')), (($t + (-1)**!$enc * $k) % 26)->list; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is vigenere('lemon', 'attackatdawn', 1), 'lxfopvefrnhr', + 'encoding example from Wiki'; + is vigenere('lemon', 'lxfopvefrnhr', 0), 'attackatdawn', + 'decoding example from Wiki'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} -- cgit