473,586 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple hashing

Hello all,

I'm using MD5 hashing in my application to give unique values to huge
list of items my application receives, originally every item's name was

difficult to use as an id for this item although its unique but because

it had certain characters and variable lengths I ended up using MD5
hashing of the name.
My question: is there a simpler way of doing hashing than MD5 which is
32bit but still guarantee uniqueness for almost 10 billion records?
Thank you.
Maya.

Jul 24 '06 #1
8 4568
There are many.. but with a guarantee for 10 billion records...
Just an example, a 32 bit hash may generate 2^32 unique hash values.
If you have 30 byte key, you will get 2^240 possibile keys mapped to 2^32
unique has values.
That leaves you about 2^208 possible keys for one hash value.. it's quite
impossible to not have collisions.

You could check FNV hash at http://www.isthe.com/chongo/tech/comp/fnv/
I've used it for a sometime and it's fast and quite simple.
It's good for small strings also, but AFAIK there is collision analysis for
it.

Also a simple CRC32 could be (re)considered. Empiric tests show that a CRC32
with 18M data has
about 38000 collisions. CRC48 almost none. But everything depends on your
data.

Here you can find others hashing functions with examples:

http://eternallyconfuzzled.com/tuts/hashing.html


"Maya" <kf****@gmail.c omha scritto nel messaggio
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hello all,

I'm using MD5 hashing in my application to give unique values to huge
list of items my application receives, originally every item's name was

difficult to use as an id for this item although its unique but because

it had certain characters and variable lengths I ended up using MD5
hashing of the name.
My question: is there a simpler way of doing hashing than MD5 which is
32bit but still guarantee uniqueness for almost 10 billion records?
Thank you.
Maya.

Jul 24 '06 #2
On 24 Jul 2006 02:24:52 -0700, "Maya" <kf****@gmail.c omwrote:
>Hello all,

I'm using MD5 hashing in my application to give unique values to huge
list of items my application receives, originally every item's name was

difficult to use as an id for this item although its unique but because

it had certain characters and variable lengths I ended up using MD5
hashing of the name.
My question: is there a simpler way of doing hashing than MD5 which is
32bit but still guarantee uniqueness for almost 10 billion records?
Thank you.
Maya.
You don't say if you are using MD5 for security reasons. Both MD2 and
MD4 are broken in security, but they are both simpler and faster then
MD5.

There are a large number of non-cryptographic hashes around, FNV
(http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash) and others, which
are much simpler and much faster but are not cryptographical ly secure.
If collision avoidance is important to you then you may need to do a
test to see how collision prone any possible replacement is. FNV has
a number of sizes, including 128 bit and 256 bit. The 256 bit size
should be collision free, even if the 128 bit hash fails the test.

To reiterate, MD2, MD4 and FNV are *not* cryptographical ly secure. If
security is involved you need to stick with MD5 or upgrade to SHA-1
or better.

rossum

Jul 24 '06 #3
Maya wrote:
Hello all,

I'm using MD5 hashing in my application to give unique values to huge
list of items my application receives, originally every item's name was

difficult to use as an id for this item although its unique but because

it had certain characters and variable lengths I ended up using MD5
hashing of the name.
My question: is there a simpler way of doing hashing than MD5 which is
32bit but still guarantee uniqueness for almost 10 billion records?
This is like saying you want to take the numbers from 1 to 100 and assign each a
unique hash code from 1 to 10 - it can't be done. 32 bits can represent at most
around 4 billion numbers. It would take 34 bits to even count your 10 billion
records. So uniqueness is not even theoretically possible here.

HTH,
-rick-
Jul 24 '06 #4
"Maya" <kf****@gmail.c omha scritto nel messaggio
My question: is there a simpler way of doing hashing than MD5 which is
32bit but still guarantee uniqueness for almost 10 billion records?
There is no guarantee that an hashing algorithm produces unique results.
You can be (really) unluky and get the same MD5 for just only 2 records.

--

Free .Net Reporting Tool - http://www.neodatatype.net
Jul 24 '06 #5
"Maya" <kf****@gmail.c omwrote in message news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
My question: is there a simpler way of doing hashing than MD5 which is
32bit but still guarantee uniqueness for almost 10 billion records?
Maya,
Actually - I'm pretty sure an MD5 is actually 128-bit, not 32bit. Most visual representations of it are 32 DIGIT. But those digits
are hexadecimal - hence 128-bit. 2^128 is huge... far higher than 10 billion.

--
Adam
Jul 24 '06 #7
You could try using something like this, and just increase the maxSize to a
point where you get a key of sufficient length:

public static string GetUniqueKey()
{
int maxSize = 8;
char[] chars = new char[62];
string a;
a = "abcdefghijklmn opqrstuvwxyzABC DEFGHIJKLMNOPQR STUVWXYZ1234567 890";
chars = a.ToCharArray() ;
int size = maxSize;
byte[] data = new byte[1];
RNGCryptoServic eProvider crypto = new RNGCryptoServic eProvider();
crypto.GetNonZe roBytes(data);
size = maxSize;
data = new byte[size];
crypto.GetNonZe roBytes(data);
StringBuilder result = new StringBuilder(s ize);
foreach (byte b in data)
{ result.Append(c hars[b % (chars.Length - 1)]); }
return result.ToString ();
}
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Maya" wrote:
Hello all,

I'm using MD5 hashing in my application to give unique values to huge
list of items my application receives, originally every item's name was

difficult to use as an id for this item although its unique but because

it had certain characters and variable lengths I ended up using MD5
hashing of the name.
My question: is there a simpler way of doing hashing than MD5 which is
32bit but still guarantee uniqueness for almost 10 billion records?
Thank you.
Maya.

Jul 24 '06 #8
Thank you guys, this was very useful to me.

Maya.

Peter wrote:
You could try using something like this, and just increase the maxSize to a
point where you get a key of sufficient length:

public static string GetUniqueKey()
{
int maxSize = 8;
char[] chars = new char[62];
string a;
a = "abcdefghijklmn opqrstuvwxyzABC DEFGHIJKLMNOPQR STUVWXYZ1234567 890";
chars = a.ToCharArray() ;
int size = maxSize;
byte[] data = new byte[1];
RNGCryptoServic eProvider crypto = new RNGCryptoServic eProvider();
crypto.GetNonZe roBytes(data);
size = maxSize;
data = new byte[size];
crypto.GetNonZe roBytes(data);
StringBuilder result = new StringBuilder(s ize);
foreach (byte b in data)
{ result.Append(c hars[b % (chars.Length - 1)]); }
return result.ToString ();
}
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Maya" wrote:
Hello all,

I'm using MD5 hashing in my application to give unique values to huge
list of items my application receives, originally every item's name was

difficult to use as an id for this item although its unique but because

it had certain characters and variable lengths I ended up using MD5
hashing of the name.
My question: is there a simpler way of doing hashing than MD5 which is
32bit but still guarantee uniqueness for almost 10 billion records?
Thank you.
Maya.
Jul 26 '06 #9

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

Similar topics

4
8879
by: Seth | last post by:
I want to create a simple hash function that can hash strings. Currently I'm storing passwords as strings in a DB but want to store them as a hash. I don't need any proper standardised hashing e.g. MD4 or MD5. I also want to be able to write the function completely using VB Script (therefore no components etc) I'm thinking along the lines...
2
1999
by: Pat | last post by:
I want to look for some one-to-one hashing function. In C++, any one-to-one hashing function?
1
3003
by: snowteo | last post by:
Hi,I have to do this exercises can you help me: 1)Write a program to implement exetendible hashing.If the table is small enough to fin in main memory,how does its performance compare with open and closed hasing? 2)A basic program consists of a series of statements,each of which is numbered in ascending order.Control is passed by use of a goto...
11
3421
by: Wm. Scott Miller | last post by:
Hello all! We are building applications here and have hashing algorithms to secure secrets (e.g passwords) by producing one way hashes. Now, I've read alot and I've followed most of the advice that made sense. One comment I've seen alot about is "securing the hashing routine" but no-one explains how to accomplish this. So how do I secure...
19
3820
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as dictionary keys, based on their content, not their identity. Is this feasible using the arrays directly, or do I need to wrap them in a struct that...
3
2028
by: Dara Durum | last post by:
Hi ! Py2.4, Win32. I need to optimize a program that have a speciality: hash (MD5/SHA1) the file contents (many files). Now I do this in a simple python program, because (what a pity) the FSUM utility died in a file with unicode filename... (It is unknown error: I used alternate file name, but it not found).
1
4401
by: Tinku | last post by:
Hi friends I know Static Hashing and i know about Dynamic Hashing, still i have problem to make program with Dynamic Hashing I am new in "C" world, please help me, my problem is: i have to make program in Dynamic hashing i have to store int value in nodes user only enter int value by this value i have to find hash key and make symbol...
15
2992
by: Vinodh | last post by:
I am reading about hashing techniques. The map data structure available in C++ STL uses hashing techniques?
5
1191
by: Oriane | last post by:
Hi, With Asp.net 2.0, when a internet user logs in with a "login authentication form", is the password encrypted when it is sent to the server ? Is is hashed ? Best regards
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7954
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...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
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...
1
5710
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...
0
5390
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...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.