From 5bad9e1d3f0f8babbac8fcdb7c6dfbf9b6fc44e3 Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Wed, 29 Jan 2020 14:23:47 -0500 Subject: 45 --- challenge-045/dave-jacoby/perl/ch-1.pl | 42 ++++++++++++++++++++++++++++++++++ challenge-045/dave-jacoby/perl/ch-2.pl | 11 +++++++++ 2 files changed, 53 insertions(+) create mode 100644 challenge-045/dave-jacoby/perl/ch-1.pl create mode 100644 challenge-045/dave-jacoby/perl/ch-2.pl 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>; +} -- cgit From 5b84ac296508669a8a58113d38bcf469b222835e Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Wed, 29 Jan 2020 14:27:30 -0500 Subject: Blog Post! --- challenge-045/dave-jacoby/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-045/dave-jacoby/blog.txt 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 -- cgit