Ly, 65 bytes
Try it online!
I'm enjoying learning Ly, so even though this is an old challenge I decided to give it a shot...
This is pretty brute force and the result isn't short compared to other entries. But it does show how to do things like
if-then conditional blocks in Ly, so maybe someone will find it useful?
This bit reads in a line of input as codepoints, reverses the stack, then loops through each character/codepoint. At the end of the loop the character is printed, rot13'd or not.
The first thing to do is duplicate the character with
: since we need to do two operations and it's easier to make a copy of the character on the stack now and then do the first one. That first test checks to see if the current character is in
"A-Z". It does that by stacking the results from 4 comparisons,
>z. Then it combines those
0|1 results mathematically to figure out if we're in the right range.
Then the pattern I've found works for
if-then is used to conditionally apply the rot-13 logic only when we get an alphabetic character. That pattern is
...test...[p...then-code...0]p. So in this case that's these bits.
And the code to apply the rotation starts by figuring out and remembering if the character is uppercase or not. After the
s command, the backup cell will be
1|0 to indicated whether or not the character is uppercase.
After that, the code adds 13 to the codepoint, then constructs what the max codepoint value is. It's either
z depending on the case of the original character. The
l command pushed the backup cell (upper/lower flag) onto the stack so we use that to switch the
z if necessary.
Once that max codepoint is on the stack the code conditionally subtracts
26 if the rotated number it too high.
At that point, the character we want to print is on top of the stack.