diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-01-30 11:56:13 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-30 11:56:13 +0000 |
| commit | f26939dd0f88c9f8250b2bdd149d419f8e4faeef (patch) | |
| tree | eb3a220e180dd6dca8c99aa594173cdf099d0698 | |
| parent | 53dc2163cc1c6d024afde4b1ea1a19e52c9b0041 (diff) | |
| parent | 5b84ac296508669a8a58113d38bcf469b222835e (diff) | |
| download | perlweeklychallenge-club-f26939dd0f88c9f8250b2bdd149d419f8e4faeef.tar.gz perlweeklychallenge-club-f26939dd0f88c9f8250b2bdd149d419f8e4faeef.tar.bz2 perlweeklychallenge-club-f26939dd0f88c9f8250b2bdd149d419f8e4faeef.zip | |
Merge pull request #1181 from jacoby/master
Got it done
| -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>; +} |
