package crockford
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
Crockford Base32 encoding for OCaml
Install
dune-project
Dependency
Authors
Maintainers
Sources
crockford-1.0.0.tbz
md5=3e26e20be39cf0c98588dd256d8be3fd
sha512=90407e12691cd55cd32d556baf250d505f108fd0a4f83ed044f757829fe75dce481321d7d14eea7e93c882286ea7904029c3a2b5250da8b4981ea52e593d14e5
Description
An OCaml implementation of Douglas Crockford's Base32 encoding with ISO 7064 checksum support. Provides encoding and decoding of int64 values to URI-friendly base32 strings, with optional checksum validation, padding, splitting, and random ID generation.
Published: 13 Nov 2025
README
Crockford Base32 Encoding for OCaml
An OCaml implementation of Douglas Crockford's Base32 encoding with ISO 7064 checksum support. Provides encoding and decoding of int64 values to URI-friendly base32 strings, with optional checksum validation, padding, splitting, and random ID generation. Ported from https://github.com/front-matter/commonmeta.
Installation
opam install crockfordOr add to your dune-project:
(package
(depends
(crockford)))Usage
Basic Encoding and Decoding
(* Encode a number *)
let encoded = Crockford.encode 1234567890L in
(* "16jkpa2" *)
(* Decode back to number *)
let decoded = Crockford.decode "16jkpa2" in
(* 1234567890L *)With Checksum
(* Encode with checksum *)
let encoded = Crockford.encode ~checksum:true 1234567890L in
(* "16jkpa2d" *)
(* Decode and validate checksum *)
let decoded = Crockford.decode ~checksum:true "16jkpa2d" in
(* 1234567890L - or raises Checksum_mismatch if invalid *)Formatted Output
(* Split with dashes for readability *)
let encoded = Crockford.encode ~split_every:4 1234567890L in
(* "16jk-pa2" *)
(* With minimum length (zero-padded) *)
let encoded = Crockford.encode ~min_length:10 1234L in
(* "000000016j" *)Random ID Generation
Random.self_init ();
(* Generate random IDs *)
let id = Crockford.generate ~length:8 ~checksum:true () in
(* e.g., "a3x7m9q5" *)
(* Generate formatted IDs *)
let id = Crockford.generate ~length:16 ~split_every:4 ~checksum:true () in
(* e.g., "7n2q-8xkm-5pwt-3hr9" *)Normalization
(* Handles common character confusions *)
let decoded = Crockford.decode "ILO" in (* Treated as "110" *)
let decoded = Crockford.decode "16-JK-PA" in (* Dashes ignored *)License
MIT License
Author
Anil Madhavapeddy anil@recoil.org (based on code from https://github.com/front-matter/commonmeta)
Links
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page