The Atbash cipher is a substitution cipher that maps each letter to its mirror position in the alphabet: 'a' maps to 'z', 'b' maps to 'y', 'c' maps to 'x', and so on. Non-letter characters (spaces, digits, punctuation) remain unchanged. The output is always lowercase. Return null for null input and an empty string for empty input.
Examples:
Input: text = 'abc'
Output: 'zyx'
Explanation: a->z, b->y, c->x
Input: text = 'hello'
Output: 'svool'
Explanation: h->s, e->v, l->o, l->o, o->l
Input: text = 'xyz'
Output: 'cba'
Explanation: x->c, y->b, z->a
Input: text = 'Hello World'
Output: 'svool dliow'
Explanation: Letters are encoded, space is preserved, output is lowercase
Input: text = ''
Output: ''
Explanation: Empty string returns empty string
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.