module Crockford
Overview
this implements Crockford encoding, as defined at https://www.crockford.com/base32.html
Extended Modules
Defined in:
crockford.crConstant Summary
-
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 Method Summary
-
#decode(str : String, encoding : Encoding = DEFAULT) : UInt64
Decodes the given Crockford base-32 encoded string.
- #decode128(str : String, encoding : Encoding = DEFAULT) : UInt128
- #decode128?(str : String, encoding : Encoding = DEFAULT) : UInt128 | Nil
-
#decode?(str : String, encoding : Encoding = DEFAULT) : UInt64 | Nil
Decodes the given Crockford base-32 encoded string.
- #decode_big(str : String, encoding : Encoding = DEFAULT) : BigInt
- #decode_big?(str : String, encoding : Encoding = DEFAULT) : BigInt | Nil
-
#encode(number : Int, encoding : Encoding = DEFAULT) : String
Takes a non-negative integer and encodes it with Crockford's base-32 encoding.
Instance Method Detail
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.
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.
Takes a non-negative integer and encodes it with Crockford's base-32 encoding. Returns a String representing the encoded value.