diff options
| -rw-r--r-- | challenge-045/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-045/dave-jacoby/perl/ch-1.pl | 42 | ||||
| -rw-r--r-- | challenge-045/dave-jacoby/perl/ch-2.pl | 11 |
3 files changed, 54 insertions, 0 deletions
diff --git a/challenge-045/dave-jacoby/blog.txt b/challenge-045/dave-jacoby/blog.txt new file mode 100644 index 0000000000..2be6e34888 --- /dev/null +++ b/challenge-045/dave-jacoby/blog.txt @@ -0,0 +1 @@ +https://jacoby.github.io/2020/01/29/challenge-45-cyphers-and-quines.html diff --git a/challenge-045/dave-jacoby/perl/ch-1.pl b/challenge-045/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..697a290942 --- /dev/null +++ b/challenge-045/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature qw{ say postderef signatures }; +no warnings qw{ experimental::postderef experimental::signatures }; + +use JSON; +my $json = JSON->new; + +my $string = 'The quick brown fox jumps over the lazy dog'; + +my $input = scalar @ARGV ? join ' ', @ARGV : $string; + +my $code = encypher($input); +say $code; + +sub encypher ( $plaintext ) { + $plaintext = lc $plaintext; + $plaintext =~ s/[^a-z]//gmx; + my @work; + + while ( length $plaintext >= 8 ) { + my $eight = substr $plaintext, 0, 8; + $plaintext =~ s/\w{8}//mix; + push @work, $eight; + } + push @work, $plaintext; + + my @cyphertext; + + for my $i ( 0 .. scalar @work - 1 ) { + my $word = $work[$i]; + for my $j ( 0 .. length $word ) { + my $letter = substr $word, $j, 1; + next unless scalar $letter; + $cyphertext[$j][$i] = $letter; + } + } + + return join ' ', map { join '', $_->@* } @cyphertext; +} diff --git a/challenge-045/dave-jacoby/perl/ch-2.pl b/challenge-045/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..387d32008e --- /dev/null +++ b/challenge-045/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,11 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Cwd qw{abs_path}; + +my $file = abs_path($0); +if ( -f $file && open my $fh, '<', $file ) { + print join '', <$fh>; +} |
