id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-encryption > apcsaAtbashCipher
prev  |  next  |  chance

Given an input String, "reverse" all the letter characters by swapping them with their mirror characters at the other end of the alphabet. So, 'A' becomes 'Z', 'a' becomes 'z', 'B' becomes 'Y' and so forth. Also reverse all the digits: '0' becomes '9', '1' becomes '8' etc. Notice from the data, this algorithm is its own decryptor as well because if it is run again on ciphertext, the original plaintext is restored.


Yes, you could do this with 63 if statements.  Please don't - you are setting yourself up for a truly miserable time with this series of exercises.

Note that the input will contain both lowercase and uppercase letters, and that the case of the input letters must be preserved in the output.  Characters that are neither letters nor numbers should appear unchanged in the output.
HINT
Character.isLetter, Character.isLowerCase, Character.isUpperCase, and Character.isDigit are all useful.

apcsaAtbashCipher("abcd") → "zyxw"
apcsaAtbashCipher("zyxw") → "abcd"
apcsaAtbashCipher("AbCdEfGhIjKlMnOpQrStUvWxYz") → "ZyXwVuTsRqPoNmLkJiHgFeDcBa"

...Save, Compile, Run (ctrl-enter)

public String apcsaAtbashCipher(String str) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 320

Copyright Nick Parlante 2017 - privacy