@inventivetalent/optimus-ts
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

Knuth's integer hashing based id obfuscation

Build Status Latest build

This is a port of jenssegers/optimus PHP library for Javascript. It works on the browser as well as node.

Installation

npm install optimus-js
bower install optimus-js

Usage

To initialize the library you need 3 things.

  • Large prime number lower than 2147483647 (prime)
  • The inverse prime so that (prime * inverse) & 2147483647 = 1
  • A large random number lower than 2147483647

for more info and a command line too to generate these values please refer the original project

using the above parameters you can create instances of Optimus(prime, inverse, random)

var Optimus = require('optimus');

var optimus = new Optimus(1580030173, 59260789, 1163945558);

After that you can use encode and decode methods to encode/decode positive integers ranging from (0 to 2147483647).

var hash = optimus.encode(25);
var original = optimus.decode(hash);

Warning: Please note that this library only provides obfuscation and not encryption.

Package Sidebar

Install

npm i @inventivetalent/optimus-ts

Weekly Downloads

6

Version

0.2.1

License

MIT

Unpacked Size

21.9 kB

Total Files

17

Last publish

Collaborators

  • inventivetalent