Efficient integer hashing library using Knuth's multiplicative method for Javascript and Typescript, perfect for obfuscating sequential numbers.
Repository
Current version released
2 years ago
inthash
Integer Hashing Library based on Knuth’s multiplicative hashing method for Javascript(& Typescript).
Installation
Node.js
npm install inthash
import { Hasher } from "inthash";
//
Deno
import { Hasher } from "https://deno.land/x/inthash/mod.ts";
//
Usage
3 values are required before using inthash.
- Prime
- Inverse
- Xor (Random Number)
Fortunately, we provide the CLI tool also.
$ npx inthash
Prime : 1288792847
Inverse : 327558127
Xor : 74691595
$ npx inthash | pbcopy
then paste to your code! :-) good luck.
require('inthash').create(1288792847, 327558127, 74691595)
Copy the output code and paste it into your project.
There are only two methods. encode
and decode
.
const hasher = new Hasher({
bits: 53, // Javascript, Number.MAX_SAFE_INTEGER
prime: "6456111708547433",
inverse: "3688000043513561",
xor: "969402349590075",
});
const encoded = hasher.encode(100); // 6432533451586367
const decoded = hasher.decode(encoded); // 100
Done!
bigint(20)
MySQL :-)