views:

372

answers:

3

The top result on google http://csharpfeeds.com/post/4382/A%5Fshorter%5Fand%5FURL%5Ffriendly%5FGUID.aspx will get one down to 00amyWGct0y_ze4lIsj2Mw

Can it go smaller than that?

+1  A: 

A GUID looks like this c9a646d3-9c61-4cb7-bfcd-ee2522c8f633 - that's 32 hex digits, each encoding 4 bits, so 128 bits in total

A base64 encoding uses 6 bits per symbol, which is easy to achieve with URL safe chars to give a 22 char encoded string. As others have noted, you could with with 73 url safe symbols and encoded as a base 73 number to give 21 chars.

Paul Dixon
How did you derive the "6 bits out of an URL-safe character" bit?
Dominic Rodger
There aren't 127 URL safe characters, so assumed 6 bits would be the maximum.
Paul Dixon
6 bits is base64, which the original link went to. If you can get more than 64 characters, say, 85, you could convert the 128-bit number to base 85 and get down to 20 characters. It just won't be as nice as base64.
retracile
Base64 uses 6 bits. You would have to replace the "/" from the list of Base64 characters, though.
David
+1 - that makes sense, thanks!
Dominic Rodger
@Dominic: Base64 = 6 bits per byte of actual data.
Spencer Ruport
A: 

Guid can be represented as byte array, use Base64 encode to convert it, so it would be little bit shorter.

Dewfy
+4  A: 

Looks like there are only 73 characters that can be used unescaped in a URL. IF that's the case, you could convert the 128-bit number to base 73, and have a 21 character URL.

IF you can find 85 legal characters, you can get down to a 20 character URL.

retracile
So we're saving 9 characters on the URL? I find it actually easier to read/recite the hexadecimal than something like 00amyWGct0y_ze4lIsj2Mw
hometoast
@hometoast: Yeah, well, that didn't seem to be a constraint for the OP. ;)
retracile