New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

bit-entropy

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bit-entropy

Calculates the bit-level entropy of a string or ID space given its cardinality and length.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

bit-entropy

Canonical URL:
https://alexstevovich.com/a/bit-entropy-nodejs

Software URL:
https://midnightcitylights.com/software/bit-entropy-nodejs

A utility to calculate the bit-level entropy of a string or identifier space based on its cardinality (number of unique symbols) and length.

This utility is based on information theory and provides a quick way to calculate the amount of information (in bits) that can be encoded using a string of a given length over a finite character set.

Installation

npm install bit-entropy

Example

import { bitEntropy } from 'bit-entropy';

console.log(bitEntropy(2, 8)); // 8 bits (e.g., binary byte)
console.log(bitEntropy(16, 32)); // 128 bits (e.g., UUID v4)
console.log(bitEntropy(62, 10)); // ~59.5 bits (Base62 string of length 10)

API

bitEntropy(cardinality, length)

Calculates the entropy in bits of a string or ID space.

Parameters:

  • cardinality (number): The number of unique symbols in the character set (e.g., 62 for Base62).
  • length (number): The length of the string or identifier.

Returns:

  • number: The total entropy in bits.

Notes

  • Cardinality refers to the number of unique symbols available (e.g., 62 for Base62 encoding).
  • Length refers to the length of the string or identifier.
  • This utility is based on the formula: entropy = length * log2(cardinality).

License

Licensed under the Apache License 2.0.

Keywords

entropy

FAQs

Package last updated on 12 Nov 2025

Did you know?

Socket

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.

Install

Related posts