programs: Escape string properly

Use an unsigned char to avoid implementation-defined behavior of a right
shift.
Shift by 4 rather than 8 to get the second half of a byte.

https://bugzilla.gnome.org/show_bug.cgi?id=711457