I am writing a python program to look up a file. The file was created by a C++ program with a hash as filename ( std::hash<std::string> hash_fn ).
I know the string from which the hash was created, but I can’t find a python hash function that produces the same hash (I tried hash() and all in hashlib).
As an example, the string
file:///home/ubuntu/Untitled.skp
should give the hash:
3133433022
Unfortunately I don’t have control over the C++ program, only about the python script (or eventual python extensions).
Is it possible to find or implement the same hash function that C++ uses? Or should I try another approach?
For the most part, internal hash functions like
std::hashin C++ orthe Python hash function are not designed for external use. When you’re
designing such systems, strictly specify the hash function used, and
implement it in both systems.
If it’s too late for this, and you’ve already used
std::hash, thenabout all you can do is find the sources for it (which depending on the
compiler, may not be available), back engineer them to find the hashing
algorithm used, specify it as your hash, and reimplement it in whatever
languages needed. (You need to implement it in your own code, because
it could potentially change in the next release of your compiler.)