Metadata-Version: 2.4
Name: djb2-pure
Version: 0.1.0
Summary: Single-file pure-Python djb2 (Dan Bernstein 1991) 32-bit non-cryptographic hash.
Author: djb2-pure contributors
License: CC0-1.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Public Domain
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

# djb2-pure

A single-file pure-Python implementation of **djb2**, the classic non-cryptographic 32-bit hash
function designed by Daniel J. Bernstein (1991).

**Pure stdlib. Zero dependencies. Single file.**

## What is djb2?

djb2 is one of the simplest and most widely used string-hashing functions. It appears in
Berkeley DB, SDBM-derived libraries, the `crc32`-substitute discussions in comp.lang.c,
and Bernstein's own historical notes. Its algebraic form is:

```
h = 5381
for c in bytes:
    h = (h * 33 + c) mod 2**32
return h
```

The constant `33` and seed `5381` are the canonical Bernstein choices — no derivation
or "improved" variant. This module implements that exact algorithm verbatim.

## Install

```bash
pip install -e .
```

## Quick start

```python
from djb2_pure import djb2, djb2_hex

djb2(b"")           # 5381          (the canonical seed)
djb2(b"a")          # 177670
djb2(b"abc")        # 193485963
djb2(b"hello world")  # 894552257
djb2_hex(b"hello world")  # "3551c8c1"
```

## Public API

- `djb2(data: bytes) -> int` — returns the 32-bit hash as an unsigned integer
- `djb2_hex(data: bytes) -> str` — returns the 8-character lowercase hex string
- `Djb2` — streaming class for incremental hashing of large/chunked inputs

## Limitations

- **NOT cryptographic.** djb2 has known collisions and bias; do not use for security,
  integrity, or anywhere adversarial.
- **NOT 64-bit.** djb2 returns a 32-bit hash. For a 64-bit variant see `djb2a` (Bernstein's
  later proposal: seed `5381` with hash `h = h * 33 ^ c`, mod 2^64).
- **Streaming class wraps the same algorithm.** No novel variant; the class exists for
  parity with `hashlib` ergonomics.

## License

CC0-1.0 — public domain dedication.
