function mg_base64encode, s
compile_opt strictarr
_translate = [bindgen(26) + (byte('A'))[0], $
bindgen(26) + (byte('a'))[0], $
bindgen(10) + (byte('0'))[0], $
(byte('+'))[0], $
(byte('/'))[0]]
npadding = 3 - strlen(s) mod 3
npadding = npadding eq 3L ? 0L : npadding
b = npadding eq 0L ? byte(s) : [byte(s), bytarr(npadding)]
n = n_elements(b)
ind = bytarr(4 * n / 3)
reads, string(b, format='(' + strtrim(n, 2) + 'B08)'), ind, $
format='(' + strtrim(4 * n / 3, 2) + 'B6)'
return, string(_translate[ind[0:n_elements(ind) - npadding - 1L]]) $
+ (npadding gt 0L ? strjoin(strarr(npadding) + '=') : '')
end
s = 'Man is distinguished, not only by his reason, but by this singular ' $
+ 'passion from other animals, which is a lust of the mind, that by ' $
+ 'a perseverance of delight in the continued and indefatigable ' $
+ 'generation of knowledge, exceeds the short vehemence of any carnal ' $
+ 'pleasure.'
print, mg_base64encode(s)
end