473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

generate a unique key from a set of strings

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.

Nov 25 '06 #1
9 6407
Om*****@gmail.com wrote:
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.

---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA
Nov 25 '06 #2
It does help. One question though. If I use an MD5 hash it isn't
guaranteed to be unique is it?
pcx99 wrote:
Om*****@gmail.com wrote:
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.

---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA
Nov 25 '06 #3
Omatase wrote:
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.

---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA
Nov 25 '06 #4
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?
pcx99 wrote:
Omatase wrote:
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.

---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA
Nov 25 '06 #5
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?
pcx99 wrote:
Omatase wrote:
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.

---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA
Nov 25 '06 #6
In comp.lang.javascript message
<11**********************@j44g2000cwa.googlegroups .com>, Sat, 25 Nov
2006 09:27:47, Om*****@gmail.com wrote:
>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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/ Old RC FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 26 '06 #7
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

Dr J R Stockton wrote:
In comp.lang.javascript message
<11**********************@j44g2000cwa.googlegroups .com>, Sat, 25 Nov
2006 09:27:47, Om*****@gmail.com wrote:
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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/ Old RC FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 26 '06 #8
In comp.lang.javascript message
<11*********************@j44g2000cwa.googlegroups. com>, Sun, 26 Nov 2006
12:51:02, Omatase <Om*****@gmail.comwrote:
>Appreciate all of your comments

Dr J R Stockton wrote:
>It's a good idea to read the newsgroup and its old FAQ. See below.

--
(c)
...
So why did you not heed that one properly?

--
(c) John Stockton, Surrey, UK. REPLYyyww merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Nov 27 '06 #9
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.

Nov 28 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
29
by: Lauren Wilson | last post by:
Does anyone know how the following info is extracted from the user's computer by a Front Page form? HTTP User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107...
2
by: Chris Dunaway | last post by:
I have a web service which is accessed by a windows forms application. When the application submits a unit of work (a "job"), I want to return a job receipt or tracking number back to the...
9
by: Robert Mago | last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which is unique. I can't use the guid since its longer then 10 characthers. Also i cannot use a random number, since being...
6
by: Antonio | last post by:
Hi, I would like to have my users register their name and organization name and submit them through email so that we can generate a product key for them. But we have no idea how to generate a...
8
by: Marc | last post by:
Hi all, I have to generate and send to a printer many 6 digit alphanumeric strings. they have to be unique but I cannot check in a database or something like that if it have already been printed....
13
by: gamernaveen | last post by:
I am coding a script , where basically the user has to enter his name , choose file , file comments if required and upload. The file comments , name , filename will be stored in the database with...
15
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.