aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wilson <steven1170@zoho.eu>2019-07-01 16:32:35 +0100
committerSteven Wilson <steven1170@zoho.eu>2019-07-01 16:32:35 +0100
commit454bee157664c69f5e102a4615ae21d033e5bc4e (patch)
treee397f100019f7b39cc06447643f4a826f5299ac1
parentf1461f387051469a5169827a29f1a74b8e3e806d (diff)
downloadperlweeklychallenge-club-454bee157664c69f5e102a4615ae21d033e5bc4e.tar.gz
perlweeklychallenge-club-454bee157664c69f5e102a4615ae21d033e5bc4e.tar.bz2
perlweeklychallenge-club-454bee157664c69f5e102a4615ae21d033e5bc4e.zip
minor changes
-rw-r--r--challenge-015/steven-wilson/perl5/ch-1.pl1
-rw-r--r--challenge-015/steven-wilson/perl5/ch-2.pl16
2 files changed, 8 insertions, 9 deletions
diff --git a/challenge-015/steven-wilson/perl5/ch-1.pl b/challenge-015/steven-wilson/perl5/ch-1.pl
index daca19c68c..a59632799e 100644
--- a/challenge-015/steven-wilson/perl5/ch-1.pl
+++ b/challenge-015/steven-wilson/perl5/ch-1.pl
@@ -38,7 +38,6 @@ while ( ( @strong_primes < 10 || @weak_primes < 10 ) ) {
}
if ($is_prime) {
( $previous_prime, $current_prime ) = ( $current_prime, $next );
-
}
$next++;
}
diff --git a/challenge-015/steven-wilson/perl5/ch-2.pl b/challenge-015/steven-wilson/perl5/ch-2.pl
index 374c80b775..e9c262d986 100644
--- a/challenge-015/steven-wilson/perl5/ch-2.pl
+++ b/challenge-015/steven-wilson/perl5/ch-2.pl
@@ -42,22 +42,22 @@ say "Message $operations{$operation} to '$out_text'";
sub encode {
my ( $plaintext, $keyword ) = @_;
- my $cyphertext = "";
+ my $cyphertext;
for my $i (0..((length $plaintext) - 1)){
- (my $Mi) = grep { $alphabet[$_] eq substr($plaintext, $i, 1) } (0..@alphabet-1);
- (my $Ki) = grep { $alphabet[$_] eq substr($keyword, ($i % length $keyword), 1)} (0..@alphabet-1);
- $cyphertext .= $alphabet[($Mi + $Ki) % 26];
+ (my $mi) = grep { $alphabet[$_] eq substr($plaintext, $i, 1) } (0..@alphabet-1);
+ (my $ki) = grep { $alphabet[$_] eq substr($keyword, ($i % length $keyword), 1)} (0..@alphabet-1);
+ $cyphertext .= $alphabet[($mi + $ki) % 26];
}
return $cyphertext;
}
sub decode {
my ( $cyphertext, $keyword ) = @_;
- my $plaintext = "";
+ my $plaintext;
for my $i (0..((length $cyphertext) - 1)){
- (my $Ci) = grep { $alphabet[$_] eq substr($cyphertext, $i, 1) } (0..@alphabet-1);
- (my $Ki) = grep { $alphabet[$_] eq substr($keyword, ($i % length $keyword), 1)} (0..@alphabet-1);
- $plaintext .= $alphabet[($Ci - $Ki) % 26];
+ (my $ci) = grep { $alphabet[$_] eq substr($cyphertext, $i, 1) } (0..@alphabet-1);
+ (my $ki) = grep { $alphabet[$_] eq substr($keyword, ($i % length $keyword), 1)} (0..@alphabet-1);
+ $plaintext .= $alphabet[($ci - $ki) % 26];
}
return $plaintext;
}