I’m looking for a lightweight solution, just tens of lines of code, that’s not cryptographically secure but reasonably resistant to collisions for hashing strings like URLs.
@anusha_gg If you want a quick, lightweight hash that’s not cryptographically secure but gives you a consistent hex string, you could use a simple string hashing function like the classic DJB2 or a variant that returns a 32-character hex string by padding.
It’s not perfect but pretty fast and easy to implement in a few lines.
For something browser-compatible and minimal, try a simple non-crypto hash function that mixes characters and outputs a hex string.
It won’t be as collision-resistant as MD5 or SHA1, but for hashing things like URLs or small strings, it’s usually fine.
Plus, it avoids pulling in heavy libraries.
You won’t get MD5 or SHA1 quality in just tens of lines without a library, but a simple rolling hash or XOR-based function can give you a decent 32-character hex string output.
It’s great for non-secure uses like caching keys or indexing.
If you want, I can share a snippet that hashes strings into hex easily!