
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Efficient integer hashing library using Knuth's multiplicative method for Javascript and Typescript, perfect for obfuscating sequential numbers.
inthash is a versatile library for generating integer hash values in Javascript
and Typescript using Knuth's multiplicative method. With a user-friendly
interface, this library allows you to obfuscate predictable numbers, making it
ideal for scenarios like 'Auto Increment' values in databases. inthash supports
number
, string
, bigint
.
Node.js
npm install inthash
Deno
import { Hasher } from "https://deno.land/x/inthash/mod.ts";
Run the following command to generate random settings for your hasher:
# Node.js:
npx inthash
# Deno:
deno run jsr:@denostack/inthash/cli
# Bun
bunx inthash
# Output:
# {
# "bits": 53,
# "prime": "6456111708547433",
# "inverse": "3688000043513561",
# "xor": "969402349590075"
# }
Create a hasher with the generated settings:
const hasher = new Hasher({
bits: 53, // Javascript, Number.MAX_SAFE_INTEGER
prime: "6456111708547433", // Random Prime
inverse: "3688000043513561", // Modular Inverse
xor: "969402349590075", // Random n-bit xor mask
});
const encoded = hasher.encode(100); // result: 6432533451586367
const decoded = hasher.decode(encoded); // result: 100
// You can obfuscate predictable numbers like 'Auto Increment'!
hasher.encode(0); // 969402349590075
hasher.encode(1); // 6085136369434450
hasher.encode(2); // 4132187376469225
hasher.encode(3); // 2180123214014976
hasher.encode(Number.MAX_SAFE_INTEGER - 3); // 2024647471942759
hasher.encode(Number.MAX_SAFE_INTEGER - 2); // 6827076040726014
hasher.encode(Number.MAX_SAFE_INTEGER - 1); // 4875011878271765
hasher.encode(Number.MAX_SAFE_INTEGER); // 2922062885306540
inthash also supports string
and bigint
values:
// String input and output
const encoded = hasher.encode("100"); // "6432533451586367"
const decoded = hasher.decode(encoded); // "100"
// BigInt input and output
const encoded = hasher.encode(100n); // 6432533451586367n
const decoded = hasher.decode(encoded); // 100n
bigint(20)
To work with bigint(20)
in MySQL, you need to handle 64-bit values. The old
version of IntHash supported up to 53-bit values
(Number.MAX_SAFE_INTEGER === 2**53 - 1
). From v3 onwards, n-bit values are
supported:
# Node.js:
npx inthash -b64
# Deno:
deno run https://deno.land/x/inthash/cli.ts -b64
# Output:
# {
# "bits": 64,
# "prime": "16131139598801670337",
# "inverse": "14287487925114175297",
# "xor": "8502035541264656686"
# }
FAQs
Efficient integer hashing library using Knuth's multiplicative method for Javascript and Typescript, perfect for obfuscating sequential numbers.
The npm package inthash receives a total of 212 weekly downloads. As such, inthash popularity was classified as not popular.
We found that inthash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.