hashid — Generate short unique ids from integers
Date: 2022-12-30Last modified: 2022-12-31

Table of contents
Features
- Generate short unique ids from integers
- Create short unique ids from numbers (positive numbers & zero).
- Allow custom alphabet as well as salt — so ids are unique only to you.
- Incremental input is mangled to stay unguessable.
- Code is tiny (~350 lines), fast and does not depend on external libraries.
- Single C++ header https://raw.githubusercontent.com/schoentoon/hashidsxx/master/hashids.h
Basic usage
Encoding
// hashidsxx::Hashids hash;
// std::cout << hash.encode({123}) << std::endl; // Mj3
Decoding
// std::vector<uint64_t> output = hash.decode("Mj3");
// for (uint64_t h : output) std::cout << h << std::endl; // 123
With salt
// hashidsxx::Hashids hash("this is my salt");
// std::string id = hash.encode({1, 2, 3});
// std::vector<uint64_t> numbers = hash.decode(id);
Custom salts, alphabets and minimum lengths
// hashidsxx::Hashids hash("salt", 16, "abcdefghijklmnopqrstuvwxyz");
// std::cout << hash.encode({123456789}) << std::endl; // oavlpogkzrxrkpxd
Possible output
References
- hashids.org
- github C++11 hashids
- github .NET hashids
- [GUIDs and UUIDs are cool, but this is