Skip to content

Instantly share code, notes, and snippets.

@soulcutter
Created March 18, 2015 21:36
Show Gist options
  • Save soulcutter/4c55548bd742ff26a9a0 to your computer and use it in GitHub Desktop.
Save soulcutter/4c55548bd742ff26a9a0 to your computer and use it in GitHub Desktop.
Jenkins hash digest
class Digest::Jenkins
MAX_32_BIT = 4294967295
def self.digest(string)
hash = 0
string.each_byte do |byte|
hash += byte
hash &= MAX_32_BIT
hash += ((hash << 10) & MAX_32_BIT)
hash &= MAX_32_BIT
hash ^= hash >> 6
end
hash += (hash << 3 & MAX_32_BIT)
hash &= MAX_32_BIT
hash ^= hash >> 11
hash += (hash << 15 & MAX_32_BIT)
hash &= MAX_32_BIT
hash
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment