Skip to content

Commit

Permalink
update after feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasnorre committed Nov 17, 2024
1 parent e066fc9 commit 2e68b35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 4 additions & 8 deletions exercises/practice/atbash-cipher/.meta/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ function encode($string)

function decode($string)
{
$a_z = range('a', 'z');
$z_a = range('z', 'a');

$decodeMap = array_combine(range('z', 'a'), range('a', 'z'));
$encodedString = str_replace(' ', '', $string);

$decoded = [];
foreach (str_split($encodedString) as $char) {
// Check if the character is numeric
if ($char >= '0' && $char <= '9') {
if (isset($decodeMap[$char])) {
$decoded[] = $decodeMap[$char];
} elseif ($char >= '0' && $char <= '9') {
$decoded[] = $char;
} elseif ($char >= 'a' && $char <= 'z') {
// Map it from z_a back to a_z
$decoded[] = $a_z[array_search($char, $z_a)];
}
}

Expand Down
5 changes: 5 additions & 0 deletions exercises/practice/atbash-cipher/AtbashCipher.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ function encode(string $text): string
{
throw new \BadFunctionCallException("Implement the encode function");
}

function decode(string $text): string
{
throw new \BadFunctionCallException("Implement the decode function");
}

0 comments on commit 2e68b35

Please sign in to comment.