CJam, 43 39 35 bytes
"<~"l4"<~"q4/{:L4Ue]256b85b'N4Ue]256b85b'!f+}/LN,)<"~>"
Try it online in the [CJam interpreter].
How it works
"<~" e# Push that string.
l4q4/ e# Read aall lineinput from STDIN and split it into chunks of length 4.
{ e# For each chunk:
:LN e# Save it in LN.
4Ue] e# Right-pad it with 0's to a length of 4.
256b85b e# Convert from base 256 to base 85.
'!f+ e# Add '!' to each base-85 digit.
}/ e#
LN,) e# Push the length of the last unpadded chunk, plus 1.
< e# Keep that many chars of the last encoded chunk.
"~>" e# Push that string.
If the input was empty, N,)
will apply to the string "<~"
. Since N
initially holds a single character, the output will be correct.
We don't have to deal with z
z or pad the encoded chunks to length 5, since the input will contain only printable ASCII characters.
[CJam interpreter]: http://cjam.aditsu.net/#code=%22%3C~%22l4%2F%7B%3AL4Ue%5D256b85b'!f%2B%7D%2FL%2Chttp://cjam.aditsu.net/#code=%22%3C~%22q4%2F%7B%3AN4Ue%5D256b85b'!f%2B%7D%2FN%2C)%3C%22~%3E%22&input=Programming%20Puzzles