Created
November 20, 2009 08:44
-
-
Save Bertrand/239360 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
def smallAsciiRepresentation(digest) | |
digestParts = digest.unpack("Q2") # digest is a 128 bit buffer, cut it into two 64 bits ruby Integer | |
smallDigestPart = digestParts[0] ^ digestParts[1] # XOR the two 64 bits parts | |
smallDigest = [smallDigestPart].pack("Q") # and transform the result into a 64 bits binary buffer | |
smallDigestB64 = [smallDigest].pack("m") # b64-encode the result | |
smallID = smallDigestB64.gsub(/[\n=]/, '').gsub(/\+/,'-').gsub(/\//,'_') # and make it URL-friendly by shortening it (no '=' at the end, no '+', no '/') | |
return smallID | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment