Modified the encode method to dramatically improve performance.
Changed character lookups to use a hash of the character tables
rather than looping through each table element.