x86 machine code on DOS - 14 13 11 bytes
Well, it did get shorter again! After writing a solution for an unrelated challenge, I noticed that the same trick could be applied even here. So here we go:
00000000 b4 08 cd 21 35 01 0a 86 c2 eb f7 |...!5......| 0000000b
Commented assembly:
org 100h section .text start: mov ah,8 ; start with "read character with no echo" lop: ; this loop runs twice per character read; first with ah=8, ; so "read character with no echo", then with ah=2, so ; "write character"; the switch is performed by the xor below int 21h ; perform syscall ; ah is the syscall number; xor with 0x0a changes 8 to 2 and ; viceversa (so, switch read <=> write) ; al is the read character (when we did read); xor the low ; bit to change 0 to 1 and reverse xor ax,0x0a01 mov dl,al ; put the read (and inverted character) in dl, ; where syscall 2 looks for the character to print jmp lop ; loop
Previous solution - 13 bytes
I think it doesn't get much shorter than this. Actually, it did! Thanks to @ninjalj for shaving off one more byte.
00000000 b4 08 cd 21 34 01 92 b4 02 cd 21 eb f3 |...!4.....!..| 0000000d
This version features advanced interactivity™ - after running it from the command line, it spits out the "inverted" characters as long as you write the input digits (which are not echoed); to exit, just do a Ctrl-C.
Unlike the previous solution, this has some trouble running in DosBox - since DosBox doesn't support Ctrl-C correctly, you are forced to close the DosBox window if you want to exit. In a VM with DOS 6.0, instead, it runs as intended.
NASM source:
org 100h section .text start: mov ah,8 int 21h xor al,1 xchg dx,ax mov ah,2 int 21h jmp start
Old solution - 27 25 22 bytes
This accepted its input from the command line; runs smoothly as a .COM file in DosBox.
00000000 bb 01 00 b4 02 8a 97 81 00 80 f2 01 cd 21 43 3a |.............!C:| 00000010 1e 80 00 7c f0 c3 |...|..|
NASM input:
org 100h section .text start: mov bx, 1 mov ah, 2 loop: mov dl, byte[bx+81h] xor dl, 1 int 21h inc bx cmp bl, byte[80h] jl loop exit: ret