generate a unique key from a set of strings

O

Omatase

I have a set of about 6 or so strings that I need to use to generate a
unique hash. This hash will become the unique key in a database so the
hash has to be the same each time I gen it for any 1 set of strings.

Is there something out there that already does this written in
javascript? I didn't find anything doing a google search.
 
P

pcx99

I have a set of about 6 or so strings that I need to use to generate a
unique hash. This hash will become the unique key in a database so the
hash has to be the same each time I gen it for any 1 set of strings.

Is there something out there that already does this written in
javascript? I didn't find anything doing a google search.

If you're using php to connect to the database you can generate a key
using the md5 function of php ( http://www.php.net/md5 ). Javascript
has no such built in feature But there are open source projects that
allow you to generate a valid md5 key in javascript (
http://www.pajhome.org.uk/crypt/md5/ ).

Hope this helps.
 
O

Omatase

It does help. One question though. If I use an MD5 hash it isn't
guaranteed to be unique is it?
 
P

pcx99

Omatase said:
It does help. One question though. If I use an MD5 hash it isn't
guaranteed to be unique is it?

No. MD5 has a low "collision" rate (2^50) but it's not impossible. The
js-md5 site I linked to earlier discusses this problem and recommends
using js-sha-256 ( http://anmar.eu.org/projects/jssha2/ ) if 2^50 odds
aren't enough for you. md5 is a 128 bit key, sha256 is a 256 bit key.
 
O

Omatase

with a 256 bit key that makes the collision rate 2^100? does 256 bit
mean that's the size of the key produced, or the size of the sipher
used to create the key?
 
O

Omatase

with a 256 bit key that makes the collision rate 2^100? does 256 bit
mean that's the size of the key produced, or the size of the sipher
used to create the key?
 
D

Dr J R Stockton

In comp.lang.javascript message
Sat said:
I have a set of about 6 or so strings that I need to use to generate a
unique hash. This hash will become the unique key in a database so the
hash has to be the same each time I gen it for any 1 set of strings.

If the membership of the set of strings is unconstrained, the
requirement for a guaranteed-unique hash is that it contain at least as
much information as the strings do. It will be possible to recover the
set of strings uniquely from the hash.

Then, if at least one of the strings is unbounded in length, the unique
hash must be unbounded in length too.

Then, you might as well use the set of strings itself, perhaps
compressed by ZIP or similar.

If you want to make more progress, you must either change your question
of accept the answer to a different question.

It's a good idea to read the newsgroup and its old FAQ. See below.
 
O

Omatase

Certainly what you are saying is true. What I gather from the comments
I have received thus far is that if I want the key to be guaranteed
unique then I need to use all of each string in a way that reversing
the hash would yield the original strings. That, although of course
works, isn't highly usable as an index for a table in a database.

I am certainly ok if it isn't 'guaranteed' unique, but I need to
understand how close each particular solution gets me to that goal so
that I can make a calculated decision to balance uniqueness and
usability.

The first response I got said the 128 bit md5 has has a 'low' collision
rate of 2^50. Does that effectively mean that I would only run the risk
of duplicating a key if I have more than 1125899906842624 rows in my
table? And how large is the result of hashing some strings using a 128
bit md5 hash? Is the result itself 16 bytes? These are all simple
little things that would help me a lot when making my decision.

Appreciate all of your comments
 
O

Omatase

I'm just looking for help, if you don't want to help, but would rather
give antagonizing responses I don't think groups is a good place for
you.

Don't bother posting anything else antagonistic, I won't be checking
this article anymore.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top