commit 1a7458d1535b3d8b08202c95eda9afac26d1acbb parent 59954190eb25e0b311d53770021a01e98ae8646e Author: Samir Parikh <noreply@samirparikh.com> Date: Fri, 28 Jan 2022 17:09:38 +0000 get first 5 tests to pass Diffstat:
M | atbash-cipher/AtbashCipher.pm | | | 19 | ++++++++++++++++++- |
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/atbash-cipher/AtbashCipher.pm b/atbash-cipher/AtbashCipher.pm @@ -4,9 +4,26 @@ use warnings; use Exporter qw<import>; our @EXPORT_OK = qw<encode_atbash decode_atbash>; +my $ord_of_a = ord( 'a' ); +my $ord_of_z = ord( 'z' ); +my $ord_sum = $ord_of_a + $ord_of_z; + +my %plain_to_cipher; +my %cipher_to_plain; + +foreach ( $ord_of_a .. $ord_of_z ) { + $plain_to_cipher{ chr( $_ ) } = chr( $ord_sum - $_ ); + $cipher_to_plain{ chr( $ord_sum - $_ ) } = chr( $_ ); +} + sub encode_atbash { my ($phrase) = @_; - return undef; + my @phrase = split //, lc $phrase; + my $cipher; + foreach (@phrase) { + $cipher .= $plain_to_cipher{ $_ }; + } + return $cipher; } sub decode_atbash {