Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Nefario on April 14, 2011, 04:51:34 PM



Title: shortening hashes as a shortcut
Post by: Nefario on April 14, 2011, 04:51:34 PM
I'm using 512sha2 hashes as an id, however I would like to use a shorter string, what options are there available?

I'm thinking not using all the hash, say the first 50-100 characters to lookup the whole hash and get to work that way.

If there is a collision at say 50characters (2 hash id's have the same first 50 character) then what should I do?

Workable?

Is there a specific term for what I'm attempting to do?


Title: Re: shortening hashes as a shortcut
Post by: BitterTea on April 14, 2011, 05:27:09 PM
I'm using 512sha2 hashes as an id, however I would like to use a shorter string, what options are there available?

I'm thinking not using all the hash, say the first 50-100 characters to lookup the whole hash and get to work that way.

If there is a collision at say 50characters (2 hash id's have the same first 50 character) then what should I do?

Workable?

Is there a specific term for what I'm attempting to do?

Well, Bitcoin takes the SHA256 hash of the public key and turns it into an address by hashing with RipeMD-160 and then Base58 encoding the result (and some other stuff). Perhaps something like that?

Also, if you run Bitcoin in debug mode and double click on a txn, it will give you a very short (16 char?) string which BlockExplorer knows what to do with. Theymos might be able to tell you what exactly that string is.


Title: Re: shortening hashes as a shortcut
Post by: theymos on April 14, 2011, 05:53:47 PM
Also, if you run Bitcoin in debug mode and double click on a txn, it will give you a very short (16 char?) string which BlockExplorer knows what to do with. Theymos might be able to tell you what exactly that string is.

It's the first part the hash. Even with these few characters, collisions are rare.

50 characters is probably overkill. That's more entropy than even Bitcoin addresses. I'd probably use 12-16 bytes of high-quality randomness concatenated with the UTC time of item creation, leaving out the last four digits of the time. Then base58-encode this.

It depends on the situation, though.


Title: Re: shortening hashes as a shortcut
Post by: yomi on April 14, 2011, 08:18:38 PM
Nefario, check this:

http://blog.logeek.fr/2009/7/2/creating-small-unique-tokens-in-ruby

I found it pretty useful.


Title: Re: shortening hashes as a shortcut
Post by: Nefario on April 15, 2011, 01:58:08 AM
Thanks for the replies.

This is for the stock market, where shares that don't have a stock ticker use have a long hash id.

I'm planning to use twitter to feed post trades to, and with a character limit of 140 characters it's almost all used up just with the id. Letting twitter keep all trade records but giving users instant updates on the latest trades.

It'll also help users by having shorter strings to work with.

At least I hope it will.