base91
base91 for javascript
Fundamental
The principle is the same as base64. There are 94 printable characters in ASCII. Base64 uses 64 of them, and base91 uses 91.
Why 91? 91^2=8281 is "just" bigger than 2^13 = 8192 "a little bit", 90^2 is not enough, 92^2 is too big but not enough 2^14(=128*128), so the two-digit 91 base "Exactly" can represent 13-bit binary, and every two bytes can be compressed by one bit more than base64, thus saving a little space.
default dictionary table
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~-
Idle characters: ", ', \
Which three characters are idle can be determined according to specific needs. A certain degree of encryption can also be achieved by modifying the order of the dictionary tables.
use
base91.decode(base91.encode('abc'));
//多字节字符
base91.mb_decode(base91.mb_encode('多字节字符'));