aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Westerberg <drclaw@mac.com>2019-07-03 21:22:22 +1000
committerRuben Westerberg <drclaw@mac.com>2019-07-03 21:22:22 +1000
commit63811eb3b3df1ca743003bbeccef6e7deab78604 (patch)
tree8c419084a90edfe4cacfeb0f13f83e8d0e632f26
parent15e2258cebbeb2fb0adbfe1aae37af3f243ec681 (diff)
downloadperlweeklychallenge-club-63811eb3b3df1ca743003bbeccef6e7deab78604.tar.gz
perlweeklychallenge-club-63811eb3b3df1ca743003bbeccef6e7deab78604.tar.bz2
perlweeklychallenge-club-63811eb3b3df1ca743003bbeccef6e7deab78604.zip
Tidy up
-rw-r--r--challenge-015/ruben-westerberg/README16
-rwxr-xr-xchallenge-015/ruben-westerberg/perl5/ch-2.pl11
-rwxr-xr-xchallenge-015/ruben-westerberg/perl6/ch-2.p6 (renamed from challenge-015/ruben-westerberg/perl6/ch-2.pl)0
3 files changed, 19 insertions, 8 deletions
diff --git a/challenge-015/ruben-westerberg/README b/challenge-015/ruben-westerberg/README
index 7a30900455..e79fa3142b 100644
--- a/challenge-015/ruben-westerberg/README
+++ b/challenge-015/ruben-westerberg/README
@@ -2,8 +2,20 @@ Solution by Ruben Westerberg
ch-1.pl and ch-1.p6
===
-Simply run the program to generate the Van Eck’s sequence. If no argument is provided the first 10 items are printed.
+Run the script to generate the first 10 strong and 10 weak prime numbers
ch-2.pl and ch-2.p6
===
-Run the program to find the longest English word possible from US state abbreviations. Uses words_alpha.txt as valid word list. An external word list can be used by providing its path as a single argument.
+Encode and decode with Vigenère cipher. Ascii leters (upper and lower case), space, and sample pucctuation characters are supported.
+Operation is performed on a line by line basis from standard input and printed to standard output
+
+To encode:
+ ch-2.pl KEY
+ where KEY is the key to encode with. Input data is read from stdin
+To decode:
+ ch-2.pl -d KEY
+ where KEY is the key used for encoding. Input data is read from stdin
+
+Loopback test:
+ ./ch-2.pl "my key" | ./ch-2.pl -d "my key"
+
diff --git a/challenge-015/ruben-westerberg/perl5/ch-2.pl b/challenge-015/ruben-westerberg/perl5/ch-2.pl
index dcb7487b35..9d55175053 100755
--- a/challenge-015/ruben-westerberg/perl5/ch-2.pl
+++ b/challenge-015/ruben-westerberg/perl5/ch-2.pl
@@ -5,7 +5,7 @@ use Getopt::Long;
my $decode;
GetOptions("decode"=>\$decode);
-die "please specify a key\n" unless $ARGV[0];
+die "Please specify a key\n" unless $ARGV[0];
$|=1;
my @alpha=("a".."z","A".."Z", " ", qw<? ! . :>);
@@ -18,12 +18,11 @@ for my $c (split "", $ARGV[0]) {
my $f=$decode? 1 : -1;
while (<STDIN>) {
my (@in, @out);
- for my $c (split "") {
- push @in, grep { $c eq $alpha[$_]} @a;
- }
my $i=0;
- for my $c (@in) {
- push @out, ($c+$f*$k[$i++])%@a;
+ chomp;
+ for my $c (split "") {
+ my $in =(grep { $c eq $alpha[$_]} @a)[0];
+ push @out, ($in+$f*$k[$i++])%@a;
$i%=@k;
}
print @alpha[@out],"\n";
diff --git a/challenge-015/ruben-westerberg/perl6/ch-2.pl b/challenge-015/ruben-westerberg/perl6/ch-2.p6
index 51a8eb082d..51a8eb082d 100755
--- a/challenge-015/ruben-westerberg/perl6/ch-2.pl
+++ b/challenge-015/ruben-westerberg/perl6/ch-2.p6