Encode and decode with multiple Base32 alphabets.
-
Add the dependency to your
shard.yml:dependencies: base32: github: lemarsu/base32 version: 0.1.2
-
Run
shards install
require "base32"
# Encode Base32 with RFC_4648
Base32.encode("Hello world") # => "JBSWY3DPEB3W64TMMQQQ===="
# Decode Base32 with RFC_4648
Base32.decode("JBSWY3DPEB3W64TMMQQQ====") # => "Hello world".to_slice
# Encode Base32 with Base32Hex
Base32.encode("Hello world", Base32::Hex) # => "91IMOR3F41RMUSJCCGGG===="
# Decode Base32 with Base32Hex
Base32.decode("91IMOR3F41RMUSJCCGGG====", Base32::Hex) # => "Hello world".to_slice
# Encode Base32 with Crockford
Base32.encode("Hello world", Base32::Crockford) # => "91JPRV3F41VPYWKCCGGG"
# Decode Base32 with Crockford
Base32.decode("91JPRV3F41VPYWKCCGGG", Base32::Crockford) # => "Hello world".to_sliceYou can also configure your own and custom Base32 configuration
custom_config = Base32::Config.new(
"CAHDBNT2FUW58KQOJM3YXSZLE7PV6GR4",
padding: '!',
charmap: {
'I' => 'L',
'1' => 'L',
'0' => 'O',
}
)
Base32.encode("Hello world!", custom_config) # => "UA3ZEVDOBAVZR6Y88JJJ!!!!"
# The optional charmap is used for decoding
Base32.decode("UA3ZEVDOBAVZR6Y88JJJ!!!!", custom_config) # => "Hello world!".to_slice
Base32.decode("ua3zevdobavzr6y88jjj!!!!", custom_config) # => "Hello world!".to_slice
Base32.decode("ua3zevd0bavzr6y88jjj!!!!", custom_config) # => "Hello world!".to_slice- Fork it (https://github.com/lemarsu/base32/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
- LeMarsu - creator and maintainer