ngubin/key62

This package is abandoned and no longer maintained. The author suggests using the ngubin/key-n package instead.

Generating a unique short key from the number.

v1.0.1 2017-05-11 19:28 UTC

This package is not auto-updated.

Last update: 2020-07-09 01:42:16 UTC


README

The repository is abandoned. Use https://github.com/ngubin/key-n instead!

Key62

Generating a unique short key from the number.

A simple class for converting a number into a string key and back. You can use to shorten long numbers to unique keys.

Latest Version Total Downloads

Example Usage

Creating a key from a number:

You can only encode an integer greater than or equal to zero.

use Key62\Key62;

$key62 = new Key62();
$key = $key62->encode(100000);

Set your own character set to create keys and the minimum number of characters in the key:

If you change the minimum length of the key when encoding, then do not forget to set it with the reverse decryption of the key.

use Key62\Key62;

$characters = 'wWpJbH8nIDed1Evq5OcToF2ZuXsayz7RrtP490ixSKC3GM6gYkNVhBUQmLlfAj';
$length = 4;

$key62 = new Key62($characters, $length);
$key = $key62->encode(100000);

Getting the number from the key:

You can decode the key if all of its characters are in the class set.

use Key62\Key62;

$key62 = new Key62();
$number = $key62->decode('Gh1a');

License

This project is released under the MIT License.

© 2017 Nik Gubin, All rights reserved.