# Thread: What hashing algorithm outputs hash value as numbers only?

1. ## What hashing algorithm outputs hash value as numbers only?

Hi, Gurus. What hashing algorithm outputs hash value as numbers only? For example, if you pass a “John Q. Public” it will output 23324. If there is no such hashing, how hard is it to hire somebody to write a fairly quick one? It could be some fast hashing and then another function that creates numbers. Much obliged. wkatz.

2. What hashing algorithm outputs hash value as numbers only?
If you remove the restriction on "only", I think it would be all of them. Otherwise, it would be none of them, insofar as non-numeric data can be mapped to numbers and vice versa.

If there is no such hashing, how hard is it to hire somebody to write a fairly quick one?
Impossible, obviously. If it cannot be done, not even if you offer your soul as the price could it be done.

3. Thanks, Laserlight!

4. > What hashing algorithm outputs hash value as numbers only?
All of them I would say.

> if you pass a “John Q. Public” it will output 23324.
A very basic one would be just add up the ASCII values of all the letters.
Like 'J' + 'o' + 'h' + 'n' etc etc

Code:
```int hash ( const char *string ) {
int result = 0;
while ( *string ) result += *string++;
return result;
}```
Now, where's my money?

A good hash is another matter, one which doesn't produce obvious collisions for all anagrams for example.

5. >What hashing algorithm outputs hash value as numbers only?
That's the definition of a hash function. It maps keys to integers that can be used as the index for a table. You probably want an algorithm that's tuned for strings, like shift-add-xor:
Code:
```unsigned sax_hash ( void *key, int len )
{
unsigned char *p = key;
unsigned h = 0;
int i;

for ( i = 0; i < len; i++ )
h ^= ( h << 5 ) + ( h >> 2 ) + p[i];

return h;
}```
But any good algorithm will should work well. You seem to be mildly confused about hashing and hash tables, so browse this and this for some basic info.

6. Try pasing the characters of the string through a CRC algorithm.
The CRC of the string gives a pretty good distribution.
Just pick an appropriate sized CRC for the number of items to hash.

7. Could do a basic hash that outputs to alphanumerics then convert each char to a number and use that.

8. EDIT: Mentioned by Wraithan.

What kind of hash do you want? A checksum? Hash for a table? If you want a cryptographic hash, well, you're better off with a string. A teensy weensy integer is clearly not enough.

9. All cryptographic hashes in use result in integers. They just happen to be very BIG integers. (SHA-256, as the name says, results in 256-bit-wide integers. That's a LOT.)

Popular pages Recent additions