crockford32.nx
buildroot/runtime/crockford32.nx
about
crockford32.nx -- Crockford Base32 encoding.
Douglas Crockford 2002: a base32 variant designed for human
transcription. Removes I, L, O, U (visually similar to 1, 1,
0, V respectively) from the alphabet. Accepts mixed case +
hyphens on decode (so \"4CQ-5M4D\" and \"4cq5m4d\" both decode to
the same bytes).
Alphabet: 0123456789ABCDEFGHJKMNPQRSTVWXYZ
0 1
0123456789012345678901234567890 1
Used by:
- ULID (Universal Unique Lexicographically-sortable Identifier)
-- 26-char ID, Crockford-32 over 128 bits
- License keys, short-URL tokens, password reset tokens
- Voicemail PINs, serial numbers for hardware
Not RFC-standardised (RFC 4648 base32 is similar but uses a
different alphabet and doesn't allow hyphens/mixed case). We
ship both: base32.nx (RFC 4648) and this module (Crockford).
Invariants:
C1 Encoder output is upper-case only, no padding.
C2 Decoder accepts mixed case + '-' between groups.
C3 Round-trip exact: decode(encode(x)) == x.
dependencies 1 imports · 1 importers
imports: syscalls.nx
imported by: ulid.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 30 | const C32_ERR_SHORT: i64 = -1 |
| 31 | const C32_ERR_CHAR: i64 = -2 |
functions
| 34 | func c32_enc_char(n: i64) -> i64 { |
| 63 | func c32_dec_char(c: i64) -> i64 {
called by 1: c32_decode |
| 105 | func c32_encode(in_bytes: *u8, n: i64, out: *u8) -> i64 { |
| 131 | func c32_decode(chars: *u8, n: i64, out: *u8) -> i64 { |
| 161 | func main() -> i64 { |