将哈希码反转为字符串(不要大喊!) [英] Reverse hashcode to string (don't yell!)

查看:160
本文介绍了将哈希码反转为字符串(不要大喊!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个字符串str1,我有它的哈希码.

我想将其反转为这样的字符串:


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);

推荐答案

GetHashCode()方法返回一个数值,通常用于相等性测试.在您的情况下,您正在比较一个数字和一个不能相同的字符串.

而且您应该在这里遇到类型转换错误

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


您显然不明白什么是哈希.如果这样做的话,您将知道不可能从哈希中获取字符串.
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.


好吧,我的目标是没有像这样的哈希代码
ok i have got my goal without hashcode like this
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);


这篇关于将哈希码反转为字符串(不要大喊!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆