Encodings

Base45

RFC 9285 base45. Two bytes as three characters from the alphanumeric set of a QR code
IDbase4507 / 20base45 · 45 characters
Encoding / Base45

Base45

Fits the alphanumeric mode of a QR code.

Overhead
+48% on random bytes
Padding
none
Standard
RFC 9285
Used by
EU COVID certificates
family 1 / 20

Sample

Out
+8D VD82EK4F.KESTC
Back
"hello world!"

Access

Importimport { base45 } from "@agntn/encodings/base45"
CLIencodings encode base45 'hello world!'
Tryplayground with the sample above

Why 45? Because QR codes have an alphanumeric mode with exactly 45 characters, and it packs tighter than byte mode. Base45 turns two bytes into three of those characters, least significant first.

ts
encode("base45", "Hello!!");  // "%69 VD92EX0"
encode("base45", "ietf!");    // "QED8WEX0"

Both straight out of RFC 9285. Yes, the space is part of the alphabet. So decoding skips nothing. EU Digital COVID Certificates were base45 inside a QR code. A triple worth more than 65535 is an error. So is a lone character at the end.