4 ms·
This seems like a case where Base-85 [1] would have been a better choice than Base64. [1] http://rfc.zeromq.org/spec:32 http://rfc.zeromq.org/spec:32
by haakon 12y ago
This seems like a case where Base-85 [1] would have been a better choice than Base64.
[1] http://rfc.zeromq.org/spec:32 http://rfc.zeromq.org/spec:32
- BrandonM 12y agoWhy would you consider Z85 to be a better choice? When you take URI encoding into account, Base64 is both simpler (no need for %-encoding)[0] and more space efficient (1.75 URI characters per byte for Z85, and 1.33 for Base64)[1]. The very first line on jwt.io says, JSON Web Token (JWT) is a compact URL-safe means of...; being URI-safe appears to be an explicit design decision. [0] All but six of Z85's special characters get encoded by Javascript's encodeURIComponent: : + = ^ / ? & < > [ ] { } @ % $ # [1] URI-safe versions of Base64 (as used by JWT) use 4 characters for every 3 bytes. Z85 uses 5 characters for every four bytes, but 17 of those 85 characters require three URI characters to represent, meaning that a Z85-encoded byte requires 1.75 URI characters per byte on average: (68 * 1 + 17 * 3) / 85 = 1.4 uri_chars/char 1.4 * 5 / 4 = 1.75 uri_chars/byte
- haakon 12y agoThanks, that's a nicely explained correction.
- nly 12y agoThe HTTP standard actually allows 90 distinct octets in cookie values, but I suppose you're not going to quibble over <2% coding efficiency given Z85s other advantages. http://tools.ietf.org/html/rfc6265#section-4.1.1 http://tools.ietf.org/html/rfc6265#section-4.1.1