{"id":20094564,"url":"https://github.com/denostack/inthash","last_synced_at":"2025-07-13T21:07:00.131Z","repository":{"id":41889783,"uuid":"140250094","full_name":"denostack/inthash","owner":"denostack","description":"Efficient integer hashing library using Knuth's multiplicative method for Javascript and Typescript, perfect for obfuscating sequential numbers.","archived":false,"fork":false,"pushed_at":"2024-04-13T06:19:07.000Z","size":2396,"stargazers_count":43,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-08T14:51:41.995Z","etag":null,"topics":["deno","hashing","obfuscation","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denostack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-09T07:51:55.000Z","updated_at":"2025-06-26T03:40:16.000Z","dependencies_parsed_at":"2024-04-13T05:25:31.799Z","dependency_job_id":"8d6ceaa0-45e2-4881-9466-c91596241086","html_url":"https://github.com/denostack/inthash","commit_stats":{"total_commits":381,"total_committers":4,"mean_commits":95.25,"dds":"0.14698162729658792","last_synced_commit":"0a9ddedeea54ad7073cafebc40aa17f2048d912e"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/denostack/inthash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denostack%2Finthash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denostack%2Finthash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denostack%2Finthash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denostack%2Finthash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denostack","download_url":"https://codeload.github.com/denostack/inthash/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denostack%2Finthash/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265205667,"owners_count":23727509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","hashing","obfuscation","typescript"],"created_at":"2024-11-13T16:51:13.987Z","updated_at":"2025-07-13T21:07:00.101Z","avatar_url":"https://github.com/denostack.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inthash \u003ca href=\"https://github.com/denostack\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/denostack/images/main/logo.svg\" width=\"160\" align=\"right\" /\u003e\u003c/a\u003e\n\n\u003cp\u003e\n  \u003ca href=\"https://github.com/denostack/inthash/actions\"\u003e\u003cimg alt=\"Build\" src=\"https://img.shields.io/github/actions/workflow/status/denostack/inthash/ci.yml?branch=main\u0026logo=github\u0026style=flat-square\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/denostack/inthash\"\u003e\u003cimg alt=\"Coverage\" src=\"https://img.shields.io/codecov/c/gh/denostack/inthash?style=flat-square\" /\u003e\u003c/a\u003e\n  \u003cimg alt=\"License\" src=\"https://img.shields.io/npm/l/inthash.svg?style=flat-square\" /\u003e\n  \u003cimg alt=\"Language Typescript\" src=\"https://img.shields.io/badge/language-Typescript-007acc.svg?style=flat-square\" /\u003e\n  \u003cbr /\u003e\n  \u003ca href=\"https://jsr.io/@denostack/inthash\"\u003e\u003cimg alt=\"JSR version\" src=\"https://jsr.io/badges/@denostack/inthash?style=flat-square\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://deno.land/x/inthash\"\u003e\u003cimg alt=\"Deno version\" src=\"https://deno.land/badge/inthash/version?style=flat-square\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/inthash\"\u003e\u003cimg alt=\"NPM Version\" src=\"https://img.shields.io/npm/v/inthash.svg?style=flat-square\u0026logo=npm\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://npmcharts.com/compare/inthash?minimal=true\"\u003e\u003cimg alt=\"Downloads\" src=\"https://img.shields.io/npm/dt/inthash.svg?style=flat-square\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\ninthash is a versatile library for generating integer hash values in Javascript\nand Typescript using Knuth's multiplicative method. With a user-friendly\ninterface, this library allows you to obfuscate predictable numbers, making it\nideal for scenarios like 'Auto Increment' values in databases. inthash supports\n`number`, `string`, `bigint`.\n\n## Installation\n\n**Node.js**\n\n```bash\nnpm install inthash\n```\n\n**Deno**\n\n```ts\nimport { Hasher } from \"https://deno.land/x/inthash/mod.ts\";\n```\n\n## Usage\n\n### Generating Random Settings\n\nRun the following command to generate random settings for your hasher:\n\n```bash\n# Node.js:\nnpx inthash\n\n# Deno:\ndeno run jsr:@denostack/inthash/cli\n\n# Bun\nbunx inthash\n\n# Output:\n# {\n#   \"bits\": 53,\n#   \"prime\": \"6456111708547433\",\n#   \"inverse\": \"3688000043513561\",\n#   \"xor\": \"969402349590075\"\n# }\n```\n\n### Creating and Using a Hasher\n\nCreate a hasher with the generated settings:\n\n```ts\nconst hasher = new Hasher({\n  bits: 53, // Javascript, Number.MAX_SAFE_INTEGER\n  prime: \"6456111708547433\", // Random Prime\n  inverse: \"3688000043513561\", // Modular Inverse\n  xor: \"969402349590075\", // Random n-bit xor mask\n});\n\nconst encoded = hasher.encode(100); // result: 6432533451586367\nconst decoded = hasher.decode(encoded); // result: 100\n```\n\n![diagram](./diagram.png)\n\n```ts\n// You can obfuscate predictable numbers like 'Auto Increment'!\nhasher.encode(0); // 969402349590075\nhasher.encode(1); // 6085136369434450\nhasher.encode(2); // 4132187376469225\nhasher.encode(3); // 2180123214014976\n\nhasher.encode(Number.MAX_SAFE_INTEGER - 3); // 2024647471942759\nhasher.encode(Number.MAX_SAFE_INTEGER - 2); // 6827076040726014\nhasher.encode(Number.MAX_SAFE_INTEGER - 1); // 4875011878271765\nhasher.encode(Number.MAX_SAFE_INTEGER); // 2922062885306540\n```\n\ninthash also supports `string` and `bigint` values:\n\n```ts\n// String input and output\nconst encoded = hasher.encode(\"100\"); // \"6432533451586367\"\nconst decoded = hasher.decode(encoded); // \"100\"\n```\n\n```ts\n// BigInt input and output\nconst encoded = hasher.encode(100n); // 6432533451586367n\nconst decoded = hasher.decode(encoded); // 100n\n```\n\n### Handling MySQL `bigint(20)`\n\nTo work with `bigint(20)` in MySQL, you need to handle 64-bit values. The old\nversion of IntHash supported up to 53-bit values\n(`Number.MAX_SAFE_INTEGER === 2**53 - 1`). From v3 onwards, n-bit values are\nsupported:\n\n```bash\n# Node.js:\nnpx inthash -b64\n\n# Deno:\ndeno run https://deno.land/x/inthash/cli.ts -b64\n\n# Output:\n# {\n#   \"bits\": 64,\n#   \"prime\": \"16131139598801670337\",\n#   \"inverse\": \"14287487925114175297\",\n#   \"xor\": \"8502035541264656686\"\n# }\n```\n\n## See also\n\n- [optimus](https://github.com/jenssegers/optimus) A PHP implementation of\n  Knuth's multiplicative hashing method. inthash is inspired by and ported from\n  this library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenostack%2Finthash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenostack%2Finthash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenostack%2Finthash/lists"}