473,396 Members | 2,011 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,396 software developers and data experts.

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 4548
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.comha scritto nel messaggio
news:11**********************@m79g2000cwm.googlegr oups.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.comwrote:
>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 cryptographically 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* cryptographically 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.comha 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.comwrote in message news:11**********************@m79g2000cwm.googlegr oups.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 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890";
chars = a.ToCharArray();
int size = maxSize;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
crypto.GetNonZeroBytes(data);
size = maxSize;
data = new byte[size];
crypto.GetNonZeroBytes(data);
StringBuilder result = new StringBuilder(size);
foreach (byte b in data)
{ result.Append(chars[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 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890";
chars = a.ToCharArray();
int size = maxSize;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
crypto.GetNonZeroBytes(data);
size = maxSize;
data = new byte[size];
crypto.GetNonZeroBytes(data);
StringBuilder result = new StringBuilder(size);
foreach (byte b in data)
{ result.Append(chars[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
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....
2
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
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...
11
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...
19
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...
3
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...
1
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...
15
by: Vinodh | last post by:
I am reading about hashing techniques. The map data structure available in C++ STL uses hashing techniques?
5
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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
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,...

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.