Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mdarse/kmh
Gleam implementation of Knuth’s multiplicative hashing.
https://github.com/mdarse/kmh
Last synced: 21 days ago
JSON representation
Gleam implementation of Knuth’s multiplicative hashing.
- Host: GitHub
- URL: https://github.com/mdarse/kmh
- Owner: mdarse
- License: lgpl-2.1
- Created: 2024-09-08T17:01:35.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-08T18:09:32.000Z (3 months ago)
- Last Synced: 2024-09-13T19:51:15.314Z (3 months ago)
- Language: Gleam
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-gleam - kmh - [📚](https://hexdocs.pm/kmh/) - Implementation of Knuth’s multiplicative hashing (useful for ID obfuscation, etc.) (Packages / Cryptography)
README
# Knuth’s Multiplicative Hash
[![Package Version](https://img.shields.io/hexpm/v/kmh)](https://hex.pm/packages/kmh)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/kmh/)```sh
gleam add kmh@1
```
```gleam
import kmhpub fn main() {
// Create a new hasher with a prime, modular inverse and random number
let hasher = kmh.new(
prime: 1_580_030_173,
mod_inverse: 59_260_789,
random: 1_163_945_558,
)
// Ensure hasher parameters are valid. This is optional, but recommended.
let assert Ok(hasher) = kmh.validate(hasher)// Encode a value. For example, 15 can be a sequential internal ID that we
// don’t want to expose.
let public_id = kmh.encode(hasher, 15)
// -> 1103647397// Decode back to the original value.
let internal_id = kmh.decode(hasher, 1_103_647_397)
// -> 15
}
```> **Important note:**
> Do not reuse the hasher parameters hereabove in production. This will defeat
> the purpose of using this library.Further documentation can be found at .
## Targets
Erlang only for now. But contributions are welcome!
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
```