node.js - Encode to alphanumeric in JavaScript -
if have random string , want encode string contains alphanumeric characters, efficient way in javascript / nodejs?
obviously must possible convert output string original input string when needed.
thanks!
to encode alphanumeric string should use alphanumeric encoding. popular ones include hexadecimal (base16), base32, base 36, base58 , base62. alternatives hexadecimal used because larger alphabet results in shorter encoded string. here's info:
- hexadecimal popular because common.
- base32 , base36 useful case-insensitive encodings. base32 more human readable because removes easy-to-misread letters. base32 used in gaming , license keys.
- base58 , base62 useful case-sensitive encodings. base58 designed more human readable removing easy-to-misread letters. base58 used flickr, bitcoin , others.
in nodejs hexadecimal encoding natively supported, , can done follows:
// encode var hex = new buffer(string).tostring('hex'); // decode var string = new buffer(hex, 'hex').tostring();
it's important note there different implementations of of these. example, flickr , bitcoin use different implementations of base58.
Comments
Post a Comment