UXID.CrockfordBase32 (UXID v0.1.0) View Source
This module provides data encoding and decoding functions according to Crockford Base32
Crockford's Base 32 (UX focused - can be read over the phone) alphabet
Value | Encoding | Value | Encoding | Value | Encoding | Value | Encoding |
---|---|---|---|---|---|---|---|
0 | 0 | 9 | 9 | 18 | J | 27 | V |
1 | 1 | 10 | A | 19 | K | 28 | W |
2 | 2 | 11 | B | 20 | M | 29 | X |
3 | 3 | 12 | C | 21 | N | 30 | Y |
4 | 4 | 13 | D | 22 | P | 31 | Z |
5 | 5 | 14 | E | 23 | Q | ||
6 | 6 | 15 | F | 24 | R | (pad) | = |
7 | 7 | 16 | G | 25 | S | ||
8 | 8 | 17 | H | 26 | T |
Link to this section Summary
Functions
Decodes a base 32 encoded string with Crockford's alphabet into a binary string.
Decodes a base 32 encoded string with extended crockfordadecimal alphabet into a binary string.
Encodes a binary string into a base 32 encoded string using Crockford's alphabet.
Link to this section Functions
Specs
Decodes a base 32 encoded string with Crockford's alphabet into a binary string.
Options
The accepted options are:
:case
- specifies the character case to accept when decoding:padding
- specifies whether to require padding
The values for :case
can be:
:upper
- only allows upper case characters (default):lower
- only allows lower case characters:mixed
- allows mixed case characters
The values for :padding
can be:
true
- requires the input string to be padded to the nearest multiple of 8false
- ignores padding from the input string (default)
Examples
iex> UXID.CrockfordBase32.decode("CSQPYRK1E8")
{:ok, "foobar"}
iex> UXID.CrockfordBase32.decode("csqpyrk1e8", case: :lower)
{:ok, "foobar"}
iex> UXID.CrockfordBase32.decode("csqPyRK1E8", case: :mixed)
{:ok, "foobar"}
iex> UXID.CrockfordBase32.decode("CSQPYRK1E8======", padding: true)
{:ok, "foobar"}
Specs
Decodes a base 32 encoded string with extended crockfordadecimal alphabet into a binary string.
An ArgumentError
exception is raised if the padding is incorrect or
a non-alphabet character is present in the string.
Options
The accepted options are:
:case
- specifies the character case to accept when decoding:padding
- specifies whether to require padding
The values for :case
can be:
:upper
- only allows upper case characters (default):lower
- only allows lower case characters:mixed
- allows mixed case characters
The values for :padding
can be:
true
- requires the input string to be padded to the nearest multiple of 8 (default)false
- ignores padding from the input string
Examples
iex> UXID.CrockfordBase32.decode!("CSQPYRK1E8")
"foobar"
iex> UXID.CrockfordBase32.decode!("csqpyrk1e8", case: :lower)
"foobar"
iex> UXID.CrockfordBase32.decode!("csqPyRK1E8", case: :mixed)
"foobar"
iex> UXID.CrockfordBase32.decode!("CSQPYRK1E8======", padding: true)
"foobar"
Specs
Encodes a binary string into a base 32 encoded string using Crockford's alphabet.
Options
The accepted options are:
:case
- specifies the character case to use when encoding:padding
- specifies whether to apply padding
The values for :case
can be:
:upper
- uses upper case characters (default):lower
- uses lower case characters
The values for :padding
can be:
true
- pad the output string to the nearest multiple of 8false
- omit padding from the output string (default)
Examples
iex> UXID.CrockfordBase32.encode("foobar")
"CSQPYRK1E8"
iex> UXID.CrockfordBase32.encode("foobar", case: :lower)
"csqpyrk1e8"
iex> UXID.CrockfordBase32.encode("foobar", padding: true)
"CSQPYRK1E8======"