hashing

How do I calculate the likelyhood of a collision using md5?

I have keys that can vary in length between 1 and 256 characters*; how can I calculate the probability that any two keys will collide when using md5 (baring a brute force solution of trying each key)? * the character set is restricted to [a-z.-] ...

Does a hash function output need to be bounded less than the number of buckets?

I was reading about this person's interview "at a well-known search company". http://asserttrue.blogspot.com/2009/05/one-of-toughest-job-interview-questions.html He was asked a question which led to him implementing a hash table. He said the following: HASH = INITIAL_VALUE; FOR EACH ( CHAR IN WORD ) { HASH *= MAGIC_NUMBER HASH ^= CHAR...

Are the first 32 bits of an md5 hash just as "random" as any other substring?

I'm looking to create a 32-bit hash of some data objects. Since I don't feel like writing my own hash function and md5 is available, my current approach is to use the first 32 bits (i.e. first 8 hex digits) from an md5 hash. Is this acceptable? In other words, are the first 32 bits of an md5 hash just as "random" as any other substrin...

Effective Password Encryption

I've taken a look at the StackOverflow question, "Password Encryption / Database Layer AES or App Layer AES," and I'd like to effectively and efficiently hash my passwords on registration (web app) and then be able to check they are correct on login. I'm using VB, but comfortable using C#. I would love to use Jeff Atwood's Encryption...

C# - Determine if List<T> is dirty?

I am serializing Lists of classes which are my data entities. I have a DataProvider that contains a List. I always modify items directly within the collection. What is the best way of determining if any items in the List have changed? I am using the Compact Framework. My only current idea is to create a hash of the List (if that's po...

storing hashed passwords - base64, or hex string, or something else?

I am hashing password using the .NET System.Security.Cryptography class. It has a few algorithms for hashing, e.g. MD5, SHA1, SHA256, SHA384, SHA512 The resultant hashed value is a byte array. Should i convert it to a hex string for storing, or Convert.ToBase64String(), or to something else? (I am favoring Base64 as it is shorter than H...

How should I implement Hash for an NSMutableSet storing SQL objects?

Short description of my setup: There is an SQLObject base class which has an integer rowId. it implements isEqual by comparing its class and its rowId: return [self isKindOfClass:[otherObject class]] && self.rowId == otherObject.rowId; It implements hash by XORing its class with its rowId: return [[self class] hash] ^ self.rowId; ...

What is image hashing used for?

I hear this term sometimes and am wondering what it is used for? ...

String to Integer Hashing Function with Precision

Hi, I want to hash a char array in to an int or a long. The resulting value has to adhere to a given precision value. The function I've been using is given below: int GetHash(const char* zKey, int iPrecision /*= 6*/) { /////FROM : http://courses.cs.vt.edu/~cs2604/spring02/Projects/4/elfhash.cpp unsigned long h = 0; ...

MD5 Hashing Given a Key in C#

I've been looking for a way to hash a given string in C# that uses a predetermined key. On my adventures through the internet trying to find an example i have seen lots of MD5CryptoServiceProvider examples which seem to use a default key for the machine, but none of them that apply a specific key. I need to have a specific key to en...

Uniquely identifying URLs with one 64-bit number

This is basically a math problem, but very programing related: if I have 1 billion strings containing URLs, and I take the first 64 bits of the MD5 hash of each of them, what kind of collision frequency should I expect? How does the answer change if I only have 100 million URLs? It seems to me that collisions will be extremely rare, bu...

Are salts useless for security if the attacker knows them?

Let's say I have a table of users set up like this: CREATE TABLE `users` ( `id` INTEGER PRIMARY KEY, `name` TEXT, `hashed_password` TEXT, `salt` TEXT ) When a user is created, a randomly-generated salt is produced and stored in the database alongside the results of something like get_hash(salt + plaintext_password). I...

What's the best way to create a short hash, similiar to what tiny Url does?

I'm currently using MD5 hashes but I would like to find something that will create a shorter hash that uses just [a-z][A-Z][0-9]. It only needs to be around 5-10 characters long. Is there something out there that already does this? Update: I like the CRC32 hash. Is there a clean way of calculating it in .NET? Update2: I'm u...

Can I prevent duplicate content using md5?

I would like to prevent duplicate content. I do not want to keep a copies of content, so I decided to keep just the md5 signatures. I read that md5 collisions do happen, different content could give in the same md5 signature. Do you think md5 is enough? Should I use md5 and sh1 together? ...

Looking for a good hash table implementation in C

I am primarily interested in string keys. Can someone point me towards a library? -A ...

Is it possible for compression algorithms to generate identical output for two different files?

I would like to know if compression algorithms always generate unique output for two different sets of files. Say, I have two files A and B, and say I am applying a compression algorithm (for instance like PKZIP - this could be any compression algorithm) for each of these files to get A.zip and B.zip respectively. Is it possible for A.z...

Why should hash functions use a prime number modulus?

A long time ago, I bought a data structures book off the bargain table for $1.25. In it, the explanation for a hashing function said that it should ultimately mod by a prime number because of "the nature of math". What do you expect from a $1.25 book? Anyway, I've had years to think about the nature of math, and still can't figure it ...

Is there a way to reverse a crypt() in c?

Not sure if this is possible but I want to be able to start with a string, and then figure out what the input must be into the crypt in order to get this string out. Or maybe it's impossible, which would be the whole purpose of the thing anyways? EDIT: And yes, there is a salt in the code where I am trying this. ...

Amazon ec2 API version 2 signature encoding with c#

I am having a problem with encoding the hash for the Version 2 Signature of the ec2 API. Note my Version 1 Signature hashing works fine, but this is depreciated and I will need to move to version 2. So firstly here is the code that works... parameters is just a dictionary, what I have to do is simply sort the parameters by key and appe...

Integer generation from text: suggestions?

Alright, I have some data that I need to assign an int type identifier to dynamically. For example, here's a sample record. <Listing> <sportcode>AA</sportcode> <lgabbr>NL</lgabbr> <division>CENTRAL</division> ... <Listing> There is more data associated with this listing but these are the only fields that I can use to ...