Decrypt hash string from String.GetHashCode?

前端 未结 4 1837
深忆病人
深忆病人 2021-01-14 22:09

From this sample code from MSDN http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx

The hash code for \"abc\" is: 536991770

But how to con

相关标签:
4条回答
  • 2021-01-14 22:41

    You cannot. Hashes are one way.

    The thing with hashes is that you loose information. Independent of the length of the string, the result is always an integer. This means e.g. that getting the has of a string of 10,000 characters will also result in an integer. It is of course impossible to get the original string back from this integer.

    0 讨论(0)
  • 2021-01-14 22:50

    The is no way to get value from the hashcode. See hash-function definition. Hash values are not used to uniquely identify the original value, have values are not unique for each type of the input value.

    A hash function may map two or more keys to the same hash value. In many applications, it is desirable to minimize the occurrence of such collisions, which means that the hash function must map the keys to the hash values as evenly as possible.

    0 讨论(0)
  • 2021-01-14 22:50

    There is no way to "decrypt" the hash code. Amongst other reasons, because two different strings may very well produce the same hash code. That feature alone would make it impossible to reverse the process.

    0 讨论(0)
  • 2021-01-14 23:03

    You cannot,
    Even if you will have a table with all strings in the world and their hash code you wouldn't be able to achieve that since there are more string then ints (~4 billion ints) so there are several strings that result in the same hash code.

    0 讨论(0)
提交回复
热议问题