2

I need to one way hash alphanumeric + special chars(ascii) strings of variable length (10-20 chars). The output should be of variable length but max 25 chars long, alphanumeric and case insensitive.

Also I do not want to produce collisions so I need something collision free or at least not proven(yet?) to produce collisions.

2
  • I thought the whole point of a hash was to produce something smaller than the original data that you can use as a unique enough identifier. So collisions will always happen. I think you want something other than a hash. Commented Jun 3, 2012 at 4:24
  • @johnnycrash the hash should be smaller, but that doesn't mean it's not useful to control the size the hash. Bloom filters require changing the length of the hash. Commented Dec 4, 2014 at 3:41

1 Answer 1

1

Here is a lot of good stuff about different hash functions. I don't think any do what you are asking though. They all will have collisions.

Maybe you should check out some simple encryption algorithms.

Here is a simple encryption technique that might do what you want:

char szInput = "hash me", szOutput[20], szKey = "foo";
int i, cbKey = strlen(szKey), cbInput = strlen(szInput);

for (i=0 ; i<cbInput ; ++i)
  szOutput[i] = szInput[i]^szKey[i%cbKey];  // xor with a differnt char from the key

You won't recognize the output and it wont collide since it's reversible.

Another way that is harder to decipher, is to use the current char in the key as the count of calls you should make to rand(). Xor using the result of the last call to rand(). Since rand() always produces the same stream of numbers for a given seed, your "hash" wont't wont collide and can be decrypted.

If you want the hash to be "one way"...then throw away the key!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This is a great starting point. I guess I was searching in the wrong direction as you mentioned in your comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.