NAME
App::CrockfordBase32Utils - Utilities related to Crockford's Base 32 encoding
VERSION
This document describes version 0.005 of App::CrockfordBase32Utils (from Perl distribution App-CrockfordBase32Utils), released on 2026-01-28.
DESCRIPTION
This distribution contains the following CLIs:
Keywords: base32, base 32, crockford's base 32
FUNCTIONS
cfbase32_decode
Usage:
cfbase32_decode(%args) -> [$status_code, $reason, $payload, \%result_meta]
Decode Crockford's Base32-encoded string.
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
str => str
(No description)
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
cfbase32_encode
Usage:
cfbase32_encode(%args) -> [$status_code, $reason, $payload, \%result_meta]
Encode string to Crockford's Base32 encoding.
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
str => str
(No description)
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
cfbase32_rand
Usage:
cfbase32_rand(%args) -> [$status_code, $reason, $payload, \%result_meta]
Generate one or more Crockford Base 32 numbers.
Examples:
Generate 35 random numbers from 12 digits each, first digit(s) can be 0:
cfbase32_rand(len => 12, num => 35);Result:
[ 200, "OK", [ "6GWZVR17YXFP", "66GQZ1V967SP", "6BXPTRCWGD26", "CX57PE12V0C5", "37XKPHFWMX76", "N0076837F05J", "X801Y0PDYF7V", "32GA91BMG1KW", "S3F6NYS18HV7", "QJCG3SZME1A1", "HYF6HRE575QA", "KQ2QGJG8ZVV5", "49RGFFXA2247", "AS1A9QFK0GPR", "G6D2W6KPZPV3", "5A40WK7FTRS5", "V4XFWZ3QYHRN", "VSSKKHQ1VMGH", "DNBQV8A0PHYE", "CDDYH2XNC6ZZ", "52J63APZAVBP", "Y4MHANNGR3NX", "3TGYBFXMS7KD", "15AHNMMFVXZE", "AESWWKCF17J7", "PXEZZ3ZKTP60", "AH169RGQMTQW", "AMXWX8DPEPKD", "JSCVNX5QF6AH", "PQ6E6CNFRYAE", "9K9FSXQZTD3D", "51EDE2QMHCB3", "VK1YMTQSV788", "2WVZYW59XGZT", "N7VYPRF54F72", ], {}, ]Generate 35 random numbers from 12 digits each, first digit(s) CANNOT be 0:
cfbase32_rand(len => 12, num => 35, zero_prefix => 0);Result:
[ 200, "OK", [ "4KMM7Y637F7R", "TDPQ4JA8FE23", "414K4NTED8G8", "838SDSPRRPNG", "ZPHFSRTV2PPG", "6NP6B4NNAJ12", "HKYFWJZS6HSC", "SEZAMQC370GD", "91SXVD7KWXTG", "194ZWXXRR3HV", "JV0N4X19MWCD", "AEJVWBG8KH8A", "PS79YVY3NNN9", "HRQXJ97N0MHR", "8BCRDBB4S5F6", "K685WE8SYAM8", "6G9ERYHC96VZ", "N1VE9S94BQ1V", "W8FNSSB187YZ", "RAKH5XGJMF5C", "R2MJKNBNZ8Y0", "TD6TZB4PKNJH", "14M3YZFS2JSA", "HXBK114F4C9D", "R8J0F737PK04", "TENQJ5F4A0Y8", "P0N96Q52KZ3B", "MJFCHDV6EM9P", "HW8RPT5DJ0A7", "MYSVA2QPJ9XA", "2GA5WXEK0MMK", "AW9F4DSTCHYF", "GFPX8S18AGA0", "P0TGFATCRV37", "1G1W3J3P9B38", ], {}, ]Generate a formatted random code:
cfbase32_rand(fill_char_template => "###-###-###", len => 9); # -> [200, "OK", ["3SQ-6SA-2Y6"], {}]
This routine uses Math::Random::Secure for cryptographically secure random number generator.
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
fill_char_template => str
Provide a template for formatting number, e.g. "###-###-###".
See String::FillCharTemplate for more details.
len => int
Specify how many number of digits to generate for a number.
Note that the first digit can still be 0 unless zero_prefix is set to false.
max_base32 => str
(No description)
max_int => int
(No description)
max_len => int
Specify how many maximum number of digits to generate.
Note that the first digit can still be 0 unless zero_prefix is set to false.
min_base32 => str
(No description)
min_int => int
(No description)
min_len => int
Specify how many minimum number of digits to generate.
Note that the first digit can still be 0 unless zero_prefix is set to false.
num => uint (default: 1)
Specify how many numbers to generate.
prev_file => filename
Load list of previous numbers from the specified file.
The file will be read per-line. Empty lines and lines starting with "#" will be skipped. Non-digits will be removed first. Lowercase will be converted to uppercase. I L will be normalized to 1, O will be normalized to 0.
unique => bool
Whether to avoid generating previously generated numbers.
zero_prefix => bool (default: 1)
When generating random number of certain length range, whether the first digit is allowed to be zero.
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
cfbase32_to_num
Usage:
cfbase32_to_num(%args) -> [$status_code, $reason, $payload, \%result_meta]
Convert Crockford's Base 32 encoding to integer decimal number.
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
strs => array[str]
(No description)
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
num_to_cfbase32
Usage:
num_to_cfbase32(%args) -> [$status_code, $reason, $payload, \%result_meta]
Convert integer decimal number(s) to Crockford's Base 32 encoding.
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
nums => array[int]
(No description)
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-CrockfordBase32Utils.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-CrockfordBase32Utils.
SEE ALSO
https://www.crockford.com/base32.html
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-CrockfordBase32Utils
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.