module Crockford

Overview

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

Extended Modules

Defined in:

crockford.cr

Constant 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

Instance Method Detail

def 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.


[View source]
def decode128(str : String, encoding : Encoding = DEFAULT) : UInt128 #

[View source]
def decode128?(str : String, encoding : Encoding = DEFAULT) : UInt128 | Nil #

[View source]
def 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.


[View source]
def decode_big(str : String, encoding : Encoding = DEFAULT) : BigInt #

[View source]
def decode_big?(str : String, encoding : Encoding = DEFAULT) : BigInt | Nil #

[View source]
def 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.


[View source]