commit 8688fc56ad08537a22af8c2097fd9f76f1dc6f15 parent 84cd503deaa22246c87f796d5753dfa916891336 Author: Samir Parikh <noreply@samirparikh.com> Date: Fri, 28 Jan 2022 19:44:08 +0000 get all tests to pass Diffstat:
M | atbash-cipher/AtbashCipher.pm | | | 8 | +++++--- |
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/atbash-cipher/AtbashCipher.pm b/atbash-cipher/AtbashCipher.pm @@ -30,8 +30,7 @@ sub encode_atbash { my $cipher; my $char_position = 1; foreach (@phrase) { - # insert a space every 5 characters - $cipher .= ' ' + $cipher .= ' ' # insert a space every 5 characters if ( $char_position > 1 && ($char_position - 1) % 5 == 0); my $new_char = /[0-9]/ ? $_ : $plain_to_cipher{ $_ }; $cipher .= $new_char; @@ -42,7 +41,10 @@ sub encode_atbash { sub decode_atbash { my ($phrase) = @_; - return undef; + my @phrase = @{ sanitize_input( $phrase ) }; + my $plain; + $plain .= /[0-9]/ ? $_ : $cipher_to_plain{ $_ } foreach (@phrase); + return $plain; } 1;