Forked from giomasce/git-annex hashing functions
Last active
August 29, 2015 14:20
-
-
Save oyvholm/2897bd9537bbe4b1c8fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See docs in http://git-annex.branchable.com/internals/hashing/ and implementation in http://sources.debian.net/src/git-annex/5.20140227/Locations.hs/?hl=408#L408 | |
import hashlib | |
import struct | |
def hashdirlower(key): | |
hasher = hashlib.md5() | |
hasher.update(key) | |
digest = hasher.hexdigest() | |
return "%s/%s/" % (digest[:3], digest[3:6]) | |
def hashdirmixed(key): | |
hasher = hashlib.md5() | |
hasher.update(key) | |
digest = hasher.digest() | |
first_word = struct.unpack('<I', digest[:4])[0] | |
nums = [first_word >> (6 * x) & 31 for x in xrange(4)] | |
letters = ["0123456789zqjxkmvwgpfZQJXKMVWGPF"[i] for i in nums] | |
return "%s%s/%s%s/" % (letters[1], letters[0], letters[3], letters[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment