Hashes ...
Hashes ...
Is it possible to create hash values with Irrlicht or the Win-API? For I should use hashes instead of strings ...
i would recommend http://www.cryptopp.com/
it is easy to use, has a nice set of algorithms, and a good free license which even allows taking parts of it as public domain.
alternatively, the WinAPI apparently has a crypto API. but i would not recommend it, it seems a bit complicated and obviously is not portable. more details here (a bit down the thread):
http://www.c-plusplus.de/forum/viewtopi ... 70790.html
if you just need exactly 1 algorithm (like MD5 or SHA1), you can find a lot of portable C implementations working on char buffers on the net. example:
the original MD5 implementation: http://people.csail.mit.edu/rivest/Md5.c
one SHA1 implementation: http://www.packetizer.com/security/sha1/
it is easy to use, has a nice set of algorithms, and a good free license which even allows taking parts of it as public domain.
alternatively, the WinAPI apparently has a crypto API. but i would not recommend it, it seems a bit complicated and obviously is not portable. more details here (a bit down the thread):
http://www.c-plusplus.de/forum/viewtopi ... 70790.html
if you just need exactly 1 algorithm (like MD5 or SHA1), you can find a lot of portable C implementations working on char buffers on the net. example:
the original MD5 implementation: http://people.csail.mit.edu/rivest/Md5.c
one SHA1 implementation: http://www.packetizer.com/security/sha1/
Actually, I just need one algorithim (MD5). I don't wanna save any passwords, I just want to cut off strings.loki1985 wrote:i would recommend http://www.cryptopp.com/
it is easy to use, has a nice set of algorithms, and a good free license which even allows taking parts of it as public domain.
alternatively, the WinAPI apparently has a crypto API. but i would not recommend it, it seems a bit complicated and obviously is not portable. more details here (a bit down the thread):
http://www.c-plusplus.de/forum/viewtopi ... 70790.html
if you just need exactly 1 algorithm (like MD5 or SHA1), you can find a lot of portable C implementations working on char buffers on the net. example:
the original MD5 implementation: http://people.csail.mit.edu/rivest/Md5.c
one SHA1 implementation: http://www.packetizer.com/security/sha1/
What do you mean with "cut off strings"? Is this a hash for using strings as keys to a hash table or in some other way having a shorter handle for a string? In that case MD5 is a bad choice as are all cryptographic hashes. 128 bit hash size is overkill and hash generation is slow.
Better use some fast hash algorithm like MurmurHash.
Btw: If your strings don't overlap in memory, then the pointer is a good handle too.
Better use some fast hash algorithm like MurmurHash.
Btw: If your strings don't overlap in memory, then the pointer is a good handle too.
This is what I wanna do:haffax wrote:What do you mean with "cut off strings"? Is this a hash for using strings as keys to a hash table or in some other way having a shorter handle for a string? In that case MD5 is a bad choice as are all cryptographic hashes. 128 bit hash size is overkill and hash generation is slow.
Better use some fast hash algorithm like MurmurHash.
Btw: If your strings don't overlap in memory, then the pointer is a good handle too.
1. Read a string from a file.
2. Create a hash value from the string.
3. Save that value in a variable (ID of my object).
4. Compare the string/hash with other strings/hashes.
It would be nice if I could store the ID in a DWORD or QWORD, but I am very confused by your post, so I just say: with these informations, what would you use?
Well, it still depends on the question about why you want to hash the strings in the first place. If it is for performance gains when you compare or find these strings, MurmurHash clearly wins. Using MD5 actually makes comparison slower for most use cases compared to just using strcmp.
MD5 uses 128bit hashes which don't fit in neither DWORD nor QWORD. MurmurHash uses DWORD as hash size by default.
The problem is that there is a possiblity for collisions. The hash algorithm may create the same hash value for two distinct strings. The chance of this to happen depends on the number of strings you have. MurmurHash is pretty good at collision prevention taking aside a pretty narrow pathological case.
And since the algorithm is deterministic on any single platform, you can check for hash collisions in your code.
So for generic gaming purposes MurmurHash wins by a great margin compared to cryptographic hashes like MD5.
MD5 uses 128bit hashes which don't fit in neither DWORD nor QWORD. MurmurHash uses DWORD as hash size by default.
The problem is that there is a possiblity for collisions. The hash algorithm may create the same hash value for two distinct strings. The chance of this to happen depends on the number of strings you have. MurmurHash is pretty good at collision prevention taking aside a pretty narrow pathological case.
And since the algorithm is deterministic on any single platform, you can check for hash collisions in your code.
So for generic gaming purposes MurmurHash wins by a great margin compared to cryptographic hashes like MD5.
OK, after all I read, I will decide for ... MurmurHash. After all, I just need to compare strings, not to save passwords or something like that. Thanks for the help and the great documentation.haffax wrote:Well, it still depends on the question about why you want to hash the strings in the first place. If it is for performance gains when you compare or find these strings, MurmurHash clearly wins. Using MD5 actually makes comparison slower for most use cases compared to just using strcmp.
MD5 uses 128bit hashes which don't fit in neither DWORD nor QWORD. MurmurHash uses DWORD as hash size by default.
The problem is that there is a possiblity for collisions. The hash algorithm may create the same hash value for two distinct strings. The chance of this to happen depends on the number of strings you have. MurmurHash is pretty good at collision prevention taking aside a pretty narrow pathological case.
And since the algorithm is deterministic on any single platform, you can check for hash collisions in your code.
So for generic gaming purposes MurmurHash wins by a great margin compared to cryptographic hashes like MD5.
If you have a perfect hash and a map from hash to value, it seems that you could do it quite easily. If the hash is actually a unique identifier for an object, you could also do it trivially.loki1985 wrote:OK, looks like you need to learn something about hashes:
you NEVER can get your original value back.
Travis
i thought that was obvious. but when assuming real-world usecases of hashes, you do not have a map of the original values, so in that case it is not possible.vitek wrote:If you have a perfect hash and a map from hash to value, it seems that you could do it quite easily. If the hash is actually a unique identifier for an object, you could also do it trivially.
so, to state it more correct: you cannot get arbitrary original strings back from the hashes alone. if that was possible, i would already have developed a tool decompressing gigabytes of original data from 128 bit hashes, and become filthy rich selling it