Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

Package base32 implements RFC 4648 base32 and Crockford base32 as a pure, reusable package.

Readme View source

gno.land/p/moul/x/daily/base32/v0

RFC 4648 and Crockford base32Encode, EncodeUnpadded, EncodeCrockford, Decode, DecodeCrockford.

1import "gno.land/p/moul/x/daily/base32/v0"
2
3base32.Encode("foobar")           // "MZXW6YTBOI======"
4base32.EncodeCrockford("hello")   // "D1JPRV3F"
5base32.DecodeCrockford("d1-jprv3f")  // "hello" — case folded, hyphen ignored

Two alphabets, for two different jobs. RFC 4648 (A–Z, 2–7, = padding) is the interoperable one — use it when something else has to decode the result. Crockford (0–9, A–Z minus I, L, O, U) is designed to be read aloud and typed back: decoding folds case, reads I/L as 1 and O as 0, and ignores hyphens, so a mis-heard identifier still decodes. U is excluded to avoid accidental obscenities.

Verified against the RFC 4648 §10 vectors at every partial-group length, and the demo's pinned output is that vector set — so the example doubles as a conformance test.

Decoding is strict where it matters: leftover bits after the final byte must be zero padding, never data, so "MB" is rejected rather than silently truncated. It is lenient where it is safe: lowercase and missing padding are accepted.

Base32 costs 60% expansion (8 characters per 5 bytes) against base64's 33%. You pay that to get an alphabet that survives case-insensitive systems and the telephone.

Live demo: r/moul/x/daily/base32demo · render it at /r/moul/x/daily/base32demo/v0.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.

Overview

Package base32 implements RFC 4648 base32 and Crockford base32 as a pure, reusable package.

Two alphabets, for two different jobs:

  • RFC 4648 (A–Z, 2–7) with '=' padding — the interoperable one; use it when something else has to decode the result.
  • Crockford (0–9, A–Z minus I, L, O and U) — designed to be read aloud and typed by humans: decoding folds case, treats I/L as 1 and O as 0, and ignores hyphens, so a mis-heard identifier still decodes. U is excluded to avoid accidental obscenities.

Base32 costs 60% expansion (8 characters per 5 bytes) versus base64's 33%. You take that hit to get an alphabet that survives case-insensitive systems and being read over the phone.

A live demo of this package is at r/moul/x/daily/base32demo(/r/moul/x/daily/base32demo/v0).

Constants 2

const MaxLen

1const MaxLen = 4096
source

MaxLen bounds input so gas stays predictable.

Variables 1

var ErrTooLong, ErrCorrupt

1var (
2	// ErrTooLong is returned when input exceeds MaxLen.
3	ErrTooLong = errors.New("base32: input too long")
4	// ErrCorrupt is returned when input is not valid base32.
5	ErrCorrupt = errors.New("base32: corrupt input")
6)
source

Functions 5

func Decode

1func Decode(s string) (string, error)
source

Decode parses RFC 4648 base32, tolerating lowercase and missing padding.

func DecodeCrockford

1func DecodeCrockford(s string) (string, error)
source

DecodeCrockford parses Crockford base32, folding case, reading I/L as 1 and O as 0, and ignoring hyphens.

func Encode

1func Encode(src string) (string, error)
source

Encode returns the RFC 4648 base32 of src, with '=' padding.

func EncodeCrockford

1func EncodeCrockford(src string) (string, error)
source

EncodeCrockford returns Crockford base32, which is never padded.

func EncodeUnpadded

1func EncodeUnpadded(src string) (string, error)
source

EncodeUnpadded returns RFC 4648 base32 without padding.

Imports 2

  • errors stdlib
  • strings stdlib

Source Files 3