Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrypt hash string from String.GetHashCode?

Tags:

c#

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 convert back the "536991770" to "abc"?

like image 931
Cheung Avatar asked Aug 08 '26 00:08

Cheung


2 Answers

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.

like image 165
Andrew Bezzub Avatar answered Aug 09 '26 15:08

Andrew Bezzub


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.

like image 40
Pieter van Ginkel Avatar answered Aug 09 '26 15:08

Pieter van Ginkel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!