We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 91704f4 commit 762c038Copy full SHA for 762c038
exercises/practice/atbash-cipher/.meta/example.php
@@ -26,3 +26,24 @@ function encode($string)
26
27
return implode('', $encoded);
28
}
29
+
30
+function decode($string)
31
+{
32
+ $a_z = range('a', 'z');
33
+ $z_a = range('z', 'a');
34
35
+ $encodedString = str_replace(' ', '', $string);
36
37
+ $decoded = [];
38
+ foreach (str_split($encodedString) as $char) {
39
+ // Check if the character is numeric
40
+ if ($char >= '0' && $char <= '9') {
41
+ $decoded[] = $char;
42
+ } elseif ($char >= 'a' && $char <= 'z') {
43
+ // Map it from z_a back to a_z
44
+ $decoded[] = $a_z[array_search($char, $z_a)];
45
+ }
46
47
48
+ return implode('', $decoded);
49
+}
0 commit comments