MD5 this method is hashed into a character + number string, but now I need to hash a string into 10 binary numbers, there is no algorithm can be implemented, or you can md5 the results of conversion to 10 binary
Reply content:
MD5 this method is hashed into a character + number string, but now I need to hash a string into 10 binary numbers, there is no algorithm can be implemented, or you can md5 the results of conversion to 10 binary
In general, the conversion of a string to a decimal number can be done with the CRC32 () function ...
The advantage of this function is that it is fast ... Within my knowledge this should be the fastest built-in hash function in PHP ...
The disadvantage is that the operating system relies on ... Functions of different operating systems crc32()
will produce a value that is not the same ...
As md5()
for turning the results into decimal ... With Hexdec () is obviously not reliable ... Reasons like upstairs said not to repeat ...
Here we use another more flexible conversion function base_convert () ...
The benefit of this function is that it returns a string ... There is no overflow problem ...
The sample code is as follows ...
Hash
into ten
, as big number
p>
You can use the PHP hexdec function, the results of MD5, because Hexdec can only turn 0x7fffffff, and then big becomes float.
In addition, you do not have to use MD5, because the result of MD5 is 128bit, the PHP language itself cannot directly save such a large number of decimal. You can refer to Sdbmhash, Jshash, or C + + STL for the hash of the string itself, such as this is the Python version of the Sdbmhash
def Sdbm_hash_string (str): h = 0 m = (1 <<) for i in str:t = h h = (t << 6)% m + (t &L t;<)% m-t + ord (i) H%= m return h
Finally, by the way, do not attempt to split the MD5 results into a few paragraphs and then XOR and the like, the effect is not directly take the last few bytes.