Se attachment for a reimplementation of encode/decode that supports non ASCII chars.
Hope this helps