Mirror Cipher
Encode text with the mirror cipher:
- A lowercase letter is replaced by the letter at the mirrored position of the alphabet:
abecomesz,bbecomesy,cbecomesx, and so on up toz, which becomesa. - An uppercase letter is mirrored the same way and stays uppercase:
AbecomesZ,BbecomesY. - A digit is replaced by its mirror in
0to9:0becomes9,1becomes8, and so on. - Every other character stays as it is.
Return the encoded string. Encoding an encoded string gives the original text back.
Example 1
text "abc"
returns "zyx"
a, b, c sit at positions 1, 2, 3 from the front, so they become the letters 1, 2, 3 from the back: z, y, x.
Example 2
text "Hello, World 2024!"
returns "Svool, Dliow 7975!"
H mirrors to S, e to v, l to o, o to l; the digits 2, 0, 2, 4 mirror to 7, 9, 7, 5; the comma, space and ! stay.
Constraints
0 <= len(text) <= 60texthas letters, digits, spaces and the punctuation! ? . , ; : ' -only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- One Segment of OnesBeginner
- Percentage of Letter in StringBeginner
- Prefix of Any Word in a SentenceBeginner
- Remove Vowels from a StringBeginner
- Reverse Each WordBeginner
- Reverse Prefix of WordBeginner
- Reverse StringBeginner
- Snake Case to Camel CaseBeginner