All Projects → tuupola → Base62

tuupola / Base62

Licence: mit
Base62 encoder and decoder for arbitrary data

Projects that are alternatives of or similar to Base62

Silk V3 Decoder
kn007's blog
Stars: ✭ 1,832 (+1199.29%)
Mutual labels:  decoder, encoder
Wav
Battle tested Wav decoder/encoder
Stars: ✭ 139 (-1.42%)
Mutual labels:  decoder, encoder
Ffjpeg
a simple jpeg codec.
Stars: ✭ 58 (-58.87%)
Mutual labels:  decoder, encoder
Encore
Synonym of angkor
Stars: ✭ 19 (-86.52%)
Mutual labels:  decoder, encoder
Fuif
Free Universal Image Format
Stars: ✭ 115 (-18.44%)
Mutual labels:  decoder, encoder
Py Ubjson
Universal Binary JSON draft-12 serializer for Python
Stars: ✭ 30 (-78.72%)
Mutual labels:  decoder, encoder
Polar 3gpp Matlab
Matlab simulations of the encoder and SCL decoder for the New Radio polar code from 3GPP Release 15
Stars: ✭ 67 (-52.48%)
Mutual labels:  decoder, encoder
Utf8.js
A robust JavaScript implementation of a UTF-8 encoder/decoder, as defined by the Encoding Standard.
Stars: ✭ 449 (+218.44%)
Mutual labels:  decoder, encoder
Swift Html Entities
HTML5 spec-compliant character encoder/decoder for Swift
Stars: ✭ 130 (-7.8%)
Mutual labels:  decoder, encoder
Wx Voice
Convert audio files between Tencent apps (Weixin / Wechat, QQ) and Silk codec with other general formats such as MP3 and M4A
Stars: ✭ 93 (-34.04%)
Mutual labels:  decoder, encoder
Jave2
The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project
Stars: ✭ 570 (+304.26%)
Mutual labels:  decoder, encoder
Irremoteesp8266
Infrared remote library for ESP8266/ESP32: send and receive infrared signals with multiple protocols. Based on: https://github.com/shirriff/Arduino-IRremote/
Stars: ✭ 1,964 (+1292.91%)
Mutual labels:  decoder, encoder
Paseto
Platform-Agnostic Security Tokens implementation in GO (Golang)
Stars: ✭ 461 (+226.95%)
Mutual labels:  decoder, encoder
Reed Solomon
Reed Solomon BCH encoder and decoder
Stars: ✭ 57 (-59.57%)
Mutual labels:  decoder, encoder
Xmlcoder
Easy XML parsing using Codable protocols in Swift
Stars: ✭ 460 (+226.24%)
Mutual labels:  decoder, encoder
Iced
Blazing fast and correct x86/x64 disassembler, assembler, decoder, encoder for .NET, Rust, Python, JavaScript
Stars: ✭ 1,102 (+681.56%)
Mutual labels:  decoder, encoder
Ffmpegcommand
FFmpegCommand适用于Android的FFmpeg命令库,实现了对音视频相关的处理,能够快速的处理音视频,大概功能包括:音视频剪切,音视频转码,音视频解码原始数据,音视频编码,视频转图片或gif,视频添加水印,多画面拼接,音频混音,视频亮度和对比度,音频淡入和淡出效果等
Stars: ✭ 394 (+179.43%)
Mutual labels:  decoder, encoder
Json Rust
JSON implementation in Rust
Stars: ✭ 395 (+180.14%)
Mutual labels:  decoder, encoder
Alfalfa
Purely functional video codec, used for ExCamera and Salsify
Stars: ✭ 1,164 (+725.53%)
Mutual labels:  decoder, encoder
Cityengine Sdk
CityEngine is a 3D city modeling software for urban design, visual effects, and VR/AR production. With its C++ SDK you can create plugins and standalone apps capable to execute CityEngine CGA procedural modeling rules.
Stars: ✭ 137 (-2.84%)
Mutual labels:  decoder, encoder

Base62

This library implements base62 encoding. In addition to integers it can encode and decode any arbitrary data. This is useful for example when generating url safe random tokens for database identifiers.

Latest Version Packagist Software License Build Status Coverage

Install

Install with composer.

$ composer require tuupola/base62

This branch requires PHP 7.1 or up. The older 1.x branch supports also PHP 5.6 and 7.0.

$ composer require "tuupola/base62:^1.0"

Usage

This package has both pure PHP and GMP based encoders. By default encoder and decoder will use GMP functions if the extension is installed. If GMP is not available pure PHP encoder will be used instead.

$base62 = new Tuupola\Base62;

$encoded = $base62->encode(random_bytes(128));
$decoded = $base62->decode($encoded);

If you are encoding to and from integer use the implicit decodeInteger() and encodeInteger() methods.

$integer = $base62->encodeInteger(987654321); /* 14q60P */
print $base62->decodeInteger("14q60P"); /* 987654321 */

Note that encoding a string and an integer will yield different results.

$string = $base62->encode("987654321"); /* KHc6iHtXW3iD */
$integer = $base62->encodeInteger(987654321); /* 14q60P */

Character sets

By default Base62 uses GMP style character set. Shortcut is provided for the inverted character set which is also commonly used. You can also use any custom character set of 62 unique characters.

use Tuupola\Base62;

print Base62::GMP; /* 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz */
print Base62::INVERTED; /* 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ */

$default = new Base62(["characters" => Base62::GMP]);
$inverted = new Base62(["characters" => Base62::INVERTED]);
print $default->encode("Hello world!"); /* T8dgcjRGuYUueWht */
print $inverted->encode("Hello world!"); /* t8DGCJrgUyuUEwHT */

Speed

Install GMP if you can. It is much faster pure PHP encoder. Below benchmarks are for encoding random_bytes(128) data. BCMatch encoder is also included but it is mostly just a curiosity. It is too slow to be usable.

$ vendor/bin/phpbench run benchmarks/ --report=default

+-----------------------+------------------+-----------+
| subject               | mean             | diff      |
+-----------------------+------------------+-----------+
| benchGmpEncoder       | 110,619.469ops/s | 1.00x     |
| benchGmpEncoderCustom | 106,157.113ops/s | 1.04x     |
| benchPhpEncoder       | 373.204ops/s     | 296.40x   |
| benchBcmathEncoder    | 35.494ops/s      | 3,116.58x |
+-----------------------+------------------+-----------+

Static Proxy

If you prefer to use static syntax use the provided static proxy.

use Tuupola\Base62Proxy as Base62;

$encoded = Base62::encode(random_bytes(128));
$decoded = Base62::decode($encoded);

$encoded2 = Base62::encodeInteger(987654321);
$decoded2 = Base62::decodeInteger($encoded2);

Testing

You can run tests either manually or automatically on every code change. Automatic tests require entr to work.

$ make test
$ brew install entr
$ make watch

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].