Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a string str1 and I have got its hashcode.

I want to reverse it back to string like this:


string str1,hash1;
string str2;

str1="hello";

hash1=str1.GetHashcode();//no problem here

str2=hash1.Tostring();// could not find some thing like this
MessageBox("str1="+str1 +"IS SAME AS "+str2);
Posted
Updated 18-Aug-10 1:00am
v7
Comments
Dalek Dave 18-Aug-10 7:01am    
Minor Edit to Code Block

GetHashCode() method return a numeric value and normally used for equality testing. In your case you are comparing a number and a string those can't be same.

And you should be get a typecasting error over here

hash1=str1.GetHashcode();//no problem here
 
Share this answer
 
Comments
Khalid Sabtan 18-Aug-10 1:41am    
str1="hellow"
assume that i have got hash1=1234567
how can i get str2=hellow
Christian Graus 18-Aug-10 2:05am    
You can't. You should read a basic book and try to have some understanding of the tools you are using.
PSK_ 18-Aug-10 2:08am    
You can't get the value back to "hellow" by the default GetHashCode() method. By the way why do you want to do this?
Khalid Sabtan 18-Aug-10 2:36am    
//look at this
string str1="hellow"; char[] mychar=new char[6]; str1.CopyTo(0,mychar,0,6);
mychar[0] equal h i want to obtain the integer of mychar[0] assume it is 123 ,and it is stored in
int x like this x=convertFromcharToInteger (mychar[0]);
char[] my2ndchar=new char[5];
my2ndchar[0]=convertTochar(x);
my2ndchar[0] must be h <---this is my goal
You obviously don't understand what a hash is. If you did, you'd know that it's not possible to get a string from a hash.
 
Share this answer
 
ok i have got my goal without hashcode like this
C#
int i, j, k,len;
  long[] x = new long[128];
  char[] cc = new char[10];
  char[] cc2= new char[10];
  string str1 = "hellow",str2;
  len = str1.Length;
  str1.CopyTo(0, cc, 0, len);
  for (i = 0; i < len; i++)
  {
      x[i] = (int)cc[i];
      MessageBox.Show(x[i].ToString());
      x[i] = 2 * x[i] + 1;
  }
  str2 = "";char[] cc = new char[10];
  for (i = 0; i < len; i++)
  {
      x[i]=(x[i]-1)/2;
      cc2[i] = (char)x[i];
      MessageBox.Show(cc2[i].ToString());
      str2=str2+cc2[i];
  }
  MessageBox.Show(str2);
 
Share this answer
 
Comments
Andrew Rissing 18-Aug-10 9:54am    
Are you basically trying to encrypt or 'salt' your strings? If that's the case, I'd recommend searching Google for that.
Khalid Sabtan 18-Aug-10 10:11am    
Exactly trying to encrypt or 'salt' my strings
could you provide me the best search string in google please?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900