Improved Base64 algorithm implementation