ngubin / key62
Generating a unique short key from the number.
Installs: 4 485
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.45
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.
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.