What is DJB2 hash and what is it used for? ▾
DJB2 is a simple, fast non-cryptographic hash function created by Dan Bernstein. It uses the constant 5381 as the initial hash value and the multiplier 33 (computed as hash * 33 + c, often implemented as ((hash << 5) + hash) + c for speed). DJB2 is commonly used in hash tables, symbol tables in compilers, and simple string hashing where speed matters more than cryptographic strength.
How do I generate a DJB2 hash online? ▾
Type or paste your text into the input box on this page. The 8-character hex DJB2 hash appears instantly, computed in your browser.
Is DJB2 cryptographically secure? ▾
No. DJB2 is a non-cryptographic hash designed for speed and simplicity. Collisions are easy to find, and the function is reversible. It should never be used for passwords, signatures, or security purposes. For security applications, use SHA-256 or HMAC-SHA-256.
How fast is DJB2? ▾
DJB2 is one of the fastest hash functions in software — typically 1-3 GB/s on a modern CPU. The core operation `hash = hash * 33 + c` can be optimized to a shift-add-add sequence that modern CPUs execute in just a few cycles per byte. Its simplicity and speed make it a popular choice for hash tables and symbol tables.
DJB2 vs FNV-1a: which is better? ▾
Both are extremely fast non-cryptographic hashes with similar performance characteristics. FNV-1a generally has slightly better distribution on real-world inputs because XOR-then-multiply mixes bits more thoroughly than DJB2's multiply-then-add. DJB2 is even simpler to implement. For new code, FNV-1a is often preferred; for legacy compatibility or extreme simplicity, DJB2 is fine.
Where is DJB2 used? ▾
DJB2 is used in: GNU symbol tables (the original use), simple hash tables in C and C++ libraries, educational examples (it is often the first hash function taught due to its simplicity), and quick string-to-bucket mapping in various scripting languages and tools.
How long is a DJB2 hash? ▾
DJB2 produces a 32-bit value, displayed as 8 hexadecimal characters. The 32-bit version is the most common; 64-bit variants exist (using the constants 5381 and 33 with 64-bit arithmetic) but are less standardized.