diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2020-01-29 14:23:47 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2020-01-29 14:23:47 -0500 |
| commit | 5bad9e1d3f0f8babbac8fcdb7c6dfbf9b6fc44e3 (patch) | |
| tree | ef6e373c44c9f0a11a28a3685fabb707901f4139 /challenge-045/dave-jacoby | |
| parent | bf0d241076c0e080fd5df2f7a02a499a6d9da6d0 (diff) | |
| download | perlweeklychallenge-club-5bad9e1d3f0f8babbac8fcdb7c6dfbf9b6fc44e3.tar.gz perlweeklychallenge-club-5bad9e1d3f0f8babbac8fcdb7c6dfbf9b6fc44e3.tar.bz2 perlweeklychallenge-club-5bad9e1d3f0f8babbac8fcdb7c6dfbf9b6fc44e3.zip | |
45
Diffstat (limited to 'challenge-045/dave-jacoby')
| -rw-r--r-- | challenge-045/dave-jacoby/perl/ch-1.pl | 42 | ||||
| -rw-r--r-- | challenge-045/dave-jacoby/perl/ch-2.pl | 11 |
2 files changed, 53 insertions, 0 deletions
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>; +} |
