سؤال

I have generate a hash code as

string textBoxVal="Naresh";
int code =textBoxVal.GetHashCode();
textBox2.Text=code.ToString();

It has generated a integer value as -1078339947;

Now I want to get the Original name Naresh with this(-1078339947) hashcode. How can I do this.

هل كانت مفيدة؟

المحلول

For all practical purposes, you can't: there are lot less hash codes than there are strings, so there is more than one original value that would give your same hash code.

Hashing is, in reality, a one-way operation. If someone refers to a reversible hash, this isn't a true hash (because a hash by definition reduces an input set into one of a smaller number of output values). The closest operation to what you describe might be an encryption function - this would allow you to reverse the operation - but this is unlikely to generate as small a number as the 10-digit output in your question.

نصائح أخرى

You just can't do that! A hash code doesn't contains all the necessary informations to convert it back to a string.

There is no even guarantee that GetHashCode() will return the same thing in different environments.

Check out Eric Lippert's blog post Guidelines and rules for GetHashCode

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top