Created — forked from Bertrand/gist:239360

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:239365
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.