diff options
| -rw-r--r-- | challenge-015/steven-wilson/perl5/ch-1.pl | 1 | ||||
| -rw-r--r-- | challenge-015/steven-wilson/perl5/ch-2.pl | 16 |
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; } |
