Problem 78. Implement a ROT13 cipher
Replace each character in string s1 with the character that is shifted 13 positions from it (wrap back to the beginning if necessary). So A ? N, B ? O, and so on until Y ? L and Z ? M. Case of the output should match the case of the input, so a ? n. Non-alphabetic characters are left in place and untouched.
If
s1 = 'I love MATLAB'
then
s2 = 'V ybir ZNGYNO'
See the Wikipedia article for more info.
Solution Stats
Problem Comments
-
3 Comments
Why does the "t" not change in the second word of the second test? The correct answer has an unchanged "t"?
I'm wondering the same thing. The letters in the second word are not rotated!
OK, I see that the '& l t ;' is the < symbol, therefore, the group of four chars should stay together and not be changed, but that requires an interpretation of the input string as opposed to using the input string as is.
Solution Comments
Show commentsProblem Recent Solvers1560
Suggested Problems
-
Find relatively common elements in matrix rows
1928 Solvers
-
Renaming a field in a structure array
1435 Solvers
-
Rotate input square matrix 90 degrees CCW without rot90
594 Solvers
-
Check if number exists in vector
10455 Solvers
-
Flip the vector from right to left
8286 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!