|Classes of Kacper Rowinski
Shorten and obfuscate IDs
Using real IDs in various places - such as GET links or API payload - is generally a bad idea:
With the help of this module you can shorten and obfuscate your IDs at the same time.
Key must consist of at least two *unique* unicode characters.
The longer the dictionary - the shorter encoded ID.
Encoded ID will be made exclusively out of characters from the key. This very useful property allows to adapt your encoding to the environment. For example in SMS messages you may restrict key to US ASCII to avoid available length reduction caused by conversion to GSM 03.38 charset. Or if you want to use such ID as file/directory name in case insensitive filesystem you may want to use only lowercase letters in the key.
Encode positive integer into a string.
Note that leading
Used algorithm is a base to the length of the key conversion that maps to distinct permutation of characters. Do not consider it a strong encryption, but if you have secret and long and well shuffled key it is almost impossible to reverse-engineer real ID.
Decode string back into a positive integer.
If you provide sequential characters in key you can convert your numbers to some weird numeric systems, for example base18:
Or you can go wild just for the fun of it.
It's based on great work of bbkr and his project https://github.com/bbkr/TinyID
All examples are in example dir.