npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crypto-hashing-js

v1.1.1

Published

This is a library for hashing Strings

Downloads

4

Readme

Crypto-hashing-js

crypto-hashing-js is a JavaScript package that provides various hashing functions for strings. It includes Polynomial Hashing, Rolling Hashing, and Rabin-Karp Hashing for string matching, as well as popular cryptographic hash functions such as MD5, SHA-1, SHA-256, SHA-512, Keccak, and Blake2.

Installation

You can install crypto-hashing-js using npm:

npm install crypto-hashing-js

API

polynomialHash(s: string, base?: number, modulus?: number): number

Computes the polynomial hash value of the input string s using the given base and modulus values. The default values are 31 and 10^9 + 7, respectively.

rollingHash(s: string, base?: number, modulus?: number): [number, number]

Computes the rolling hash values of the input string s using the given base and modulus values. The function returns a tuple containing the left and right hash values.

rabinKarp(text: string, pattern: string): number[]

Finds all occurrences of the input pattern string in the text string using the Rabin-Karp hashing algorithm. The function returns an array of indices where the pattern occurs in the text.

md5(str: string): string

Computes the MD5 hash value of the input string str. The function returns the hash value as a hexadecimal string.

sha1(str: string): string

Computes the SHA-1 hash value of the input string str. The function returns the hash value as a hexadecimal string.

sha256(str: string): string

Computes the SHA-256 hash value of the input string str. The function returns the hash value as a hexadecimal string.

sha512(str: string): string

Computes the SHA-512 hash value of the input string str. The function returns the hash value as a hexadecimal string.

blake2(str: string, outputBits: number): string

Computes the Blake2 hash value of the input string str. The function takes an optional parameter outputBits to specify the desired output size, which defaults to 256 bits. The function returns the hash value as a hexadecimal string.

keccak(str: string, outputBits: number): string

Computes the Keccak hash value of the input string str. The function takes an optional parameter outputBits to specify the desired output size, which defaults to 256 bits. The function returns the hash value as a hexadecimal string.

Usage

To use hash-utils in your JavaScript project, you can import the desired functions:

import { polynomialHash, rollingHash, rabinKarp, md5, sha1, sha256, sha512, keccak, blake2 } from 'crypto-hashing-js';

Examples

Polynomial Hashing

const { polynomialHash } = require('crypto-hashing-js');

const str = 'example';
const hash = polynomialHash(str);
console.log(hash); // output: 152040089

Rolling Hashing

const { rollingHash } = require('crypto-hashing-js');

const str = 'example';
const [leftHash, rightHash] = rollingHash(str);
console.log(leftHash, rightHash); // output: 877164158 68720961

Rabin-Karp Hashing

const { rabinKarp } = require('crypto-hashing-js');

const text = 'example example';
const pattern = 'example';
const matches = rabinKarp(text, pattern);
console.log(matches); // output: [0, 8]

MD5 hashing

const { md5 } = require('crypto-hashing-js');

const str = 'example';
const hash = md5(str);
console.log(hash); // output: '1a79a4d60de6718e8e5b326e338ae533'

SHA-1 hashing

const { sha1 } = require('crypto-hashing-js');

const str = 'example';
const hash = sha1(str);
console.log(hash); // output: 'a0f1490c15e3d6e90f9a92be4ca836b83e99a4fa'

SHA-256 hashing

const { sha256 } = require('crypto-hashing-js');

const str = 'example';
const hash = sha256(str);
console.log(hash); // output: 'a0cfc76d5d3b59463dc2ffcf0ca4a3a14d9c6a772d6a685c53449e16f4c84dd5'

SHA-512 hashing

const { sha512 } = require('crypto-hashing-js');

const str = 'example';
const hash = sha512(str);
console.log(hash); // output: 'abd536...'

blake2 hashing

const { blake2 } = require('crypto-hashing-js');

const str = 'example';
const hash = blake2(str, 32);
console.log(hash); // output: 'e9b064...'

keccak hashing

const { keccak } = require('crypto-hashing-js');

const str = 'example';
const hash = keccak(str, 256);
console.log(hash); // output: '2076e37...'