public
Last active — forked from Bertrand/gist:239360

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.