Base64 encoding algorithm