Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created March 3, 2015 21:04
Show Gist options
  • Save pudquick/8e27daa40e74ec2520ab to your computer and use it in GitHub Desktop.
Save pudquick/8e27daa40e74ec2520ab to your computer and use it in GitHub Desktop.
XCode path mangling in python
import struct, hashlib
def hashStringForPath(cls, path):
hash_path = [None] * 28;
md5_digest_hex = hashlib.md5(path).digest();
first_value = struct.unpack('>Q', md5_digest_hex[:8])[0];
second_value = struct.unpack('>Q', md5_digest_hex[8:])[0];
counter = 13;
while counter >= 0:
hash_path[counter] = chr((first_value % 26) + ord('a'));
first_value = first_value / 26;
counter -= 1;
counter = 27;
while counter > 13:
hash_path[counter] = chr((second_value % 26) + ord('a'));
second_value = second_value / 26;
counter -= 1;
return ''.join(hash_path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment