Skip to content

Instantly share code, notes, and snippets.

@anuragvohraec
Forked from thejsj/pearson-hashing.js
Created July 15, 2021 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anuragvohraec/24f21add8dcb7f6c5e55bf1dc393eaf4 to your computer and use it in GitHub Desktop.
Save anuragvohraec/24f21add8dcb7f6c5e55bf1dc393eaf4 to your computer and use it in GitHub Desktop.
Pearson Hashing Function
'use strict'
// Ideally, this table would be shuffled...
// 256 will be the highest value provided by this hashing function
let table = [...new Array(256)].map((_, i) => i)
const hash8 = (message, table) => {
return message.split('').reduce((hash, c) => {
return table[(hash + c.charCodeAt(0)) % (table.length - 1)]
}, message.length % (table.length - 1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment