Hash-how to solve PHP hash function collision

Source: Internet
Author: User
Recently, I want to use the Hash function to generate a unique value based on a string, but I cannot find a useful Hash function. The value generated by Hash functions such as MD5 and SHA built in PHP is too long, I can't use it. I want to intercept it. In this way, I am worried that a hash collision will occur. I 'd like to evaluate what hash is used by high people... recently, I want to use the Hash function to generate a unique value based on a string, but I cannot find a useful Hash function. The value generated by Hash functions such as MD5 and SHA built in PHP is too long, I can't use it. I want to intercept it. I am worried that there will be a hash collision. I 'd like to evaluate what hash functions are used by high people.

Reply content:

Recently, I want to use the Hash function to generate a unique value based on a string, but I cannot find a useful Hash function. The value generated by Hash functions such as MD5 and SHA built in PHP is too long, I can't use it. I want to intercept it. I am worried that there will be a hash collision. I 'd like to evaluate what hash functions are used by high people.

Although it depends on the data to use a hash algorithm, it is difficult to connect to MD5. In fact, I really want to hear why"The value generated by the hash function is too long for me to use". If there is no assessment, simply say that based on your feelings, it would be too much.

What you may need is not a low-collision hash algorithm, but the output of the hash algorithm is compressed.String Compression Algorithm. Since the hash algorithm outputs only 16 character sets, and 94 spaces are removed from the ASCII display characters, this idea should satisfy you.

The output is shortened (that is, the size of the hash value is reduced)NecessityIncrease the probability of hash collision, and do not have any unrealistic fantasies. That is to say, no matter what your algorithm is, as long as the range is reduced, the probability of hash collision willEquivalentIncrease. So if you really need a short output hash function, you don't have to bother looking for it. This method is enough.

The title is not good either. What is the occurrence of hash collision?Inevitable, "SOLVE" the hash Collision itself does not exist.

Although hash collision is a small probability event, it cannot be feared or avoided, especially as "nonexistent ". There must be clear methods to deal with it based on application requirements. My suggestion is either to lengthen the value space of the hash algorithm or to add other comparative features as an additional supplement to the hash algorithm.

The longer the length, the smaller the chance of collision. Reducing the length will inevitably increase the chance of collision. Because you are hiding the original space into the space of the hash generation string, the length of the string determines the size of the space.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.