473,625 Members | 3,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6447
Om*****@gmail.c om 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.c om 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.javas cript message
<11************ **********@j44g 2000cwa.googleg roups.com>, Sat, 25 Nov
2006 09:27:47, Om*****@gmail.c om 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.c om/faq/ Old RC FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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 112589990684262 4 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.javas cript message
<11************ **********@j44g 2000cwa.googleg roups.com>, Sat, 25 Nov
2006 09:27:47, Om*****@gmail.c om 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.c om/faq/ Old RC FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 26 '06 #8
In comp.lang.javas cript message
<11************ *********@j44g2 000cwa.googlegr oups.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.demo n.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
18585
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 tablename; Here this function generate unique id for each row of the table. Regards..
29
3724
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 Firefox/1.0 I only ask because I believe I could use the same info as part of a scheme to generate a unique (or at least less common) serialized id code for the user's computer as part of a software locking and activation system. If I had a DLL...
2
4533
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 application. My requirements are these: 1. The receipt number must be unique (like a guid is unique) 2. The receipt must be NON sequential. 3. If possible, I'd like it to be 10 to 12 characters long. 4. If possible, I'd like to include only...
9
18109
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 random does not mean that its unique.
6
15440
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 product key something look like Microsoft's product key. In addition, I would like to have the key generated based on their name and company name. Any idea on how to go about doing this using VB.NET? Thanks in advance.
8
7196
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. the string has also to seem a random one and it cannot have an apparence of a sequence. My first approach is to do it with a decimal counter and find and use an encryption alghorithm that converts each 6 digit decimal number to a 6 digit...
13
40536
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 auto_increment id. The file gets uploaded to the server too. The problem is I want to generate a 10 digit unique code , which makes it simple for the user to download the file , he just has to enter the 10-digit code , and my script will deliver the...
15
37577
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 Different-2 string.
0
8256
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8356
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6118
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1500
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.