/hash-maker

A collection of hash and number generators for Node or Browser in pure JS.

Primary LanguageTypeScript

hash-maker

A collection of hash and number generators for Node or Browser in pure JS.

  • SHA - Creates a SHA1/224/256/384/512 hash of a message.
  • MD5 - Creates a MD5 hash of a message.
  • CRC - Createsa CRC3/16/32 hash of a message.
  • UUID - Create UUIDs verisons 1 - 5.
  • Random bytes - Random bytes of a supplied length (based on Mersenne Twister)
  • Mersenne Twister - Random number generator that can be seaded. Create 32 bit signed, unsigned or float values.
  • Random Xor Shift - Random number generator that can be seaded. Creates unsigned 32 bit values.

Installation

npm install hash-maker

Provides both CommonJS and ES modules.

SHA

SHA hash function. All SHA functions can be returned as a string, Uint8Array, Buffer or Hex string (default).

Can be imported as:

const { SHA256 } = require('hash-maker');
//
import { SHA256 } from 'hash-maker';
const hash = SHA256("0123456789",{asArray:true});
Functions Params
SHA1(message, options?)
SHA224(message, options?)
SHA256(message, options?)
SHA384(message, options?)
SHA512(message, options?)
Message to be hashed as string, Uint8Array or Buffer,
options: { asString: true || asBuffer: true || asArray: true }

MD5

MD5 hash function. MD5 functions can be returned as a string, Uint8Array, Buffer or Hex string (default).

Can be imported as:

const { MD5 } = require('hash-maker');
//
import { MD5 } from 'hash-maker';
const hash = MD5("0123456789",{asArray:true})
Functions Params
MD5(message, options?) Message to be hashed as string, Uint8Array or Buffer,
options: { asString: true || asBuffer: true || asArray: true }

CRC

CRC hash function. CRC functions can be returned as a Hex string, Uint8Array, Buffer or number (default).

Can be imported as:

const { CRC32 } = require('hash-maker');
//
import { CRC32 } from 'hash-maker';
const hash = CRC32("0123456789",{asArray:true});
Functions Params
CRC3(message, options?)
CRC16(message, options?)
CRC32(message, options?)
Message to be hashed as string, Uint8Array or Buffer,
options: { asBuffer: true || asArray: true || asHex: true }

UUID

UUID generator function. UUID functions can create verisons 1 - 5 (default 4) and can be returned as a Uint8Array, Buffer or Hex string (default).

Can be imported as:

const { UUID } = require('hash-maker');
//
import { UUID } from 'hash-maker';
const id = UUID(1,{asArray:true});
Functions Params
UUID(verison, options?) verison 1 - 5 (default 4),
options: {
seed: If seeding is needed. Must be UInt8Array or Buffer of 16 bytes,
mac: If a mac ID is needed. Must be UInt8Array or Buffer of 6 bytes. Else one is generated when needed,
asBuffer: true || asArray: true
}

Random Bytes

Random byte generator function. Functions can be returned as a Buffer or Uint8Array (default). Numbers generated with the Mersenne Twister (see below).

Can be imported as:

const { randomBytes } = require('hash-maker');
//
import { randomBytes } from 'hash-maker';
const bytes = randomBytes(12,true);
Functions Params
randomBytes(amount, asBuffer?) Bytes neede,
true to return as a Buffer

Mersenne Twister

Mersenne Twister number generator class. Can be seeded with a number or Uint32Array.

Can be imported as:

const { MERSENNETWISTER } = require('hash-maker');
//
import { MERSENNETWISTER } from 'hash-maker';
const seed; // number or Uint32Array if needed
const mt = new MERSENNETWISTER(seed);
const unsignedInt = mt.genrand_int32() // or mt.RandTwisterUnsigned() mt.random_int()
const signedInt = mt.genrand_int32i() // or mt.RandTwisterSigned()
const unsigned31Int = mt.genrand_int3i() //31 bit number
const double = mt.genrand_real1() // or mt.RandTwisterDouble()
const float1 = mt.genrand_real2() // generates a random number on [0,1)-real-interval
const float2 = mt.genrand_real3() // generates a random number on (0,1)-real-interval
const float3 = mt.genrand_res53() // generates a random number on [0,1) with 53-bit resolution
Functions Params / returns
new MERSENNETWISTER(seed?) Seed as number or Uint32Array
mt.genrand_int32()
mt.RandTwisterUnsigned()
mt.random_int()
unsigned 32 bit number
mt.genrand_int32i()
mt.RandTwisterSigned()
signed 32 bit number
mt.genrand_real1()
mt.RandTwisterDouble()
generates a random number on [0,1]-real-interval
mt.genrand_real2() generates a random number on [0,1)-real-interval
mt.genrand_real3() generates a random number on (0,1)-real-interval
mt.genrand_real3() generates a random number on [0,1) with 53-bit resolution

Random Xor Shift

Random Xor Shift number generator class. Can seeded with a number or a Uint8Array or Buffer of 4 bytes.

Can be imported as:

const { RANDOMXORSHIFT } = require('hash-maker');
//
import { RANDOMXORSHIFT } from 'hash-maker';
const seed; //number, Uint8Array or Buffer of 4 bytes
const rxs = new RANDOMXORSHIFT(seed);
const random_int = rxs.random_int();
Functions Params / returns
new RANDOMXORSHIFT(seed?) Seed as a number or a Uint8Array or Buffer of 4 bytes.
rxs.random_int() unsigned 32 bit number