aspose file tools*
The moose likes Beginning Java and the fly likes HashCode to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashCode to String" Watch "HashCode to String" New topic
Author

HashCode to String

Anthony Alberts
Greenhorn

Joined: Sep 18, 2001
Posts: 7
I am using the String method hashCode() to obtain the hash value of a specified String. I need to to convert the hash value back to the original String. Can anybody help? Essentialy this should be simple but I am stumped!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Anthony Alberts:
I am using the String method hashCode() to obtain the hash value of a specified String. I need to to convert the hash value back to the original String. Can anybody help? Essentialy this should be simple but I am stumped!

It's not only not simple, it's impossible!
First, there is no guarantee that two different Strings also differ in their hashcode. In fact there *have* to be Strings which are not equal but share the same hashcode - after all, there are much more possible values for a String than possible values for an int!
Second, there is no guarantee on how the hashcode of a String is calculated, afaik - the algorithm might very well differ strongly between JRE implementations.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Anthony Alberts
Greenhorn

Joined: Sep 18, 2001
Posts: 7
Thanks for that. I assume then that my understanding of Hash leaves much to be desired or possibly smo'kn too much of the above.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
...then you may appreciate taking a look at Roedy Green's Java Glossary on hashCode.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashCode to String