x86-16 Machine Code, IBM PC DOS, 37 bytes
Binary:
00000000: b408 cd21 3c20 7e1c 8ad0 0c20 3c61 7c0e ...!< ~.... <a|.
00000010: 3c7a 7f0a b60d 3c6e 7c02 b6f3 02d6 b402 <z....<n|.......
00000020: cd21 ebdc c3 .!...
Build and test using xxd -r
Unassembled listing:
START:
B4 08 MOV AH, 8 ; DOS API read char from STDIN (no echo)
CD 21 INT 21H ; read char into AL
3C 20 CMP AL, ' ' ; is any non-printable control char?
7E 1C JL EXIT ; if so, end
8A D0 MOV DL, AL ; save original char in DL
0C 20 OR AL, 'a'-'A' ; lowercase the char
3C 61 CMP AL, 'a' ; is char less than 'a'?
7C 0E JL WRCHR ; if so, do not convert
3C 7A CMP AL, 'z' ; is char greater than 'z'?
7F 0A JG WRCHR ; if so, do not convert
B6 0D MOV DH, 'n'-'a' ; add or subtract 13
3C 6E CMP AL, 'n' ; is char less than 'n'?
7C 02 JL ADD13 ; if so, add 13
B6 F3 MOV DH, 'a'-'n' ; otherwise add -13
ADD13:
02 D6 ADD DL, DH ; add 13 or -13
WRCHR:
B4 02 MOV AH, 2 ; DOS API write char to STDOUT
CD 21 INT 21H ; write char in DL
EB DC JMP START ; keep looping
EXIT:
C3 RET ; return to DOS
As a standalone PC DOS executable program. Input is via STDIN
, output to STDOUT
.
Re-submitting answer to conform to STDIN
challenge requirement.