code wiki / (root) / nx_crockford32.nx

nx_crockford32.nx

buildroot/runtime/nx_crockford32.nx

6624 B203 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_crockford32.nx nx_ulid.nx

imports: nx_syscalls.nx

imported by: nx_ulid.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap c32_encode c32_enc_char c32_decode c32_dec_char

structs

none

consts

36const C32_ERR_SHORT: i64 = -1
37const C32_ERR_CHAR: i64 = -2

functions

40func c32_enc_char(n: i64) -> i64
69func c32_dec_char(c: i64) -> i64
called by 1: c32_decode
111func c32_encode(in_bytes: *u8, n: i64, out: *u8) -> i64
called by 1: main calls 1: c32_enc_char
137func c32_decode(chars: *u8, n: i64, out: *u8) -> i64
called by 1: main calls 1: c32_dec_char
167func main() -> i64