module

Crockford

this implements Crockford encoding, as defined at https://www.crockford.com/base32.html

Constants

CROCKFORD_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ".bytes
DEFAULT = Encoding.new(CROCKFORD_ALPHABET, (Hash.zip(CROCKFORD_ALPHABET, (0_u8..31_u8).to_a)).merge({'I'.ord.to_u8 => 1.to_u8, 'L'.ord.to_u8 => 1.to_u8, 'O'.ord.to_u8 => 0.to_u8}))

Instance methods

decode(str : String, encoding : Encoding = DEFAULT) : UInt64

Decodes the given Crockford base-32 encoded string. Raises ArgumentError if the encoded string value does not represent a valid encoded value. Returns an Int64 representation of the encoded value.

Source
decode128(str : String, encoding : Encoding = DEFAULT) : UInt128
Source
decode128?(str : String, encoding : Encoding = DEFAULT) : UInt128 | Nil
Source
decode?(str : String, encoding : Encoding = DEFAULT) : UInt64 | Nil

Decodes the given Crockford base-32 encoded string. Returns an Int64 representation of the encoded value if the encoded string represents a valid encoded value; otherwise, returns nil.

Source
decode_big(str : String, encoding : Encoding = DEFAULT) : BigInt
Source
decode_big?(str : String, encoding : Encoding = DEFAULT) : BigInt | Nil
Source
encode(number : Int, encoding : Encoding = DEFAULT) : String

Takes a non-negative integer and encodes it with Crockford's base-32 encoding. Returns a String representing the encoded value.

Source

Nested types