Hashids works similarly to the way integers are converted to hex, but with a few exceptions:

  1. The alphabet is not base16, but base base62 by default.
  2. The alphabet is also shuffled based on salt.

This JavaScript function shows regular conversion of integers to hex. It's part of Hashids (although this is a modified example):

1) Download the file that kusk0r mentions in the first post of the thread. 2) Edit line 563 and 637 of the file CSHA256.CLS that is included in the ZIP so that the function SHA256 is renamed. I renamed it to SHADD256 for some reason. 3) In Excel 2007, go to Developer Tab, Click on Visual Basic. 4) In the IDE, do File Import File. Salted Hash Generator v.1.0 Salted Hash Generator is the FREE all-in-one tool to generate salted hash for popular hash types including MD5 and SHA1 family. Here are the currently supported hash types. Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers. It converts numbers like 347 into strings like “yr8”, or array of numbers like 27, 986 into “3kTMd”. Dec 14, 2017 Hash Generator Pro lets you easily generate hashes for your strings, as you type. Easy-to-use, intuitive interface. Algorithms supported: MD5, SHA-1, SHA-256, and SHA-512.

If we try to convert integer 1234 to hex with toHex(1234), we will get back '4d2'.

Hash Generator Pro 1 0 – Easy Hash Generator Excel

If we increase the alphabet to abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890, our output will now be shorter because there's more characters to work with — so it becomes 't5'.

If we take it one step further and shuffle the alphabet before encoding, we will get a different value. But how could we shuffle the alphabet consistently, so that with every shuffle the characters would keep the same order?

That's where Hashids uses a variation of Fisher-Yates algorithm:

The code above might look complicated, but it does one simple thing — shuffles the alphabet based on user's salt.

That way when one user passes the salt 'abc1', our alphabet becomes cUpI6isqCa0brWZnJA8wNTzDHEtLXOYgh5fQm2uRj4deM91oB7FkSGKxvyVP3l

Generator

And when another user passes 'abc2', the alphabet becomes tRvkhHx0ZefcF46YuaAqGLDKgM1W5Vp2T8n9s7BSoCjiQOdrEbJmUINywzXP3l

You can see that the shuffle is pretty good even when salt value is not that much different. This is what makes the base of Hashids work. Now we are able to encode one integer based on the salt value the user provides.

But Hashids is able to encode several integers into one id. This is done by reserving a few characters from the alphabet as separators. These characters are not used in encoding, but instead do the job of purely separating the real encoded values.

Let's say we encoded 1, 2, 3 without the salt and got 'o2fXhV'. Actual values in this output are highlighted: o2fXhV. Letters 'f' and 'h' are simply used as separators.

Letter 'o' in this case is reserved for another type of job - it acts as a lottery character to randomize incremental input. If we encode numbers as we increment them, the output is somewhat predictable:

InputOutput
1, 2, 32fXhV
1, 2, 42fXhd
1, 2, 52fXh6
1, 2, 62fXhz
1, 2, 72fXhR

So the lottery character is used to do another iteration of consistent shuffle, before starting the actual encoding. The ids then end up looking more random (with a tiny disadvantage of having that extra lottery character):

InputOutput
1, 2, 3o2fXhV
1, 2, 4pYfzhG
1, 2, 5qxfOhN
1, 2, 6rkfAhN
1, 2, 7v2fWhy

Hash Generator Pro 1 0 – Easy Hash Generator Excel Word

This is a quick overview of how Hashids is structured. Decoding is done the same way but in reverse — of course in order for that to work, Hashids itself needs the salt value from you in order to decode ids correctly.

Hash Generator Pro 1 0 – Easy Hash Generator Excel Shortcut

If you give Hashids the wrong salt and it just so happens that it decodes back to some random integers, Hashids does a quick check by encoding those integers to be sure the initial id matches. If it does not, the integers are discarded.