Skip to content

Instantly share code, notes, and snippets.

@SethVandebrooke
Last active November 14, 2017 17:36
Show Gist options
  • Save SethVandebrooke/d98913beb2fba0876206b0ba6a84152a to your computer and use it in GitHub Desktop.
Save SethVandebrooke/d98913beb2fba0876206b0ba6a84152a to your computer and use it in GitHub Desktop.
An excuse of a hash function: for hashing things you don't actually care about.
// Please note: while the returned hash would be a pain in the butt to decode, it does not ensure uniqueness for smaller strings.
// If you have a string at least 9 varying characters than it might be worth using.
function hash(s,base64){var a="";s.split('').forEach(e=>{a+=e.charCodeAt(0)>>2;});return !!base64?btoa(a):a;}
// Example: hash("mySuperSecretPassword",true); // Base64
// Output: "MjczMDIwMjkyODI1MjgyMDI1MjQyODI1MjkyMDI0MjgyODI5MjcyODI1"
// Example: hash("mySuperSecretPassword");
// Output: "273020292825282025242825292024282829272825"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment