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.
decode128(str : String, encoding : Encoding = DEFAULT) : UInt128
Sourcedecode128?(str : String, encoding : Encoding = DEFAULT) : UInt128 | Nil
Sourcedecode?(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.
decode_big(str : String, encoding : Encoding = DEFAULT) : BigInt
Sourcedecode_big?(str : String, encoding : Encoding = DEFAULT) : BigInt | Nil
Sourceencode(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.