归档抱歉归档 [英] Archived sorry archived

查看:78
本文介绍了归档抱歉归档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nteger ash(String inputString)

{

整数outputNumber = 3;

整数指数= 0;

整数lengthOfInputString = inputString.Length;

整数d = w

整数ds = 4

整数fdsf = dsd



while(index< lengthofinputstring)

{

outputnumber =(outputnumber * 3 + letters.indexof(inputstring [index]) );

index = index + 1;

}

返回outputnumber;

}





=产生==hashed =output =(integer =value)=as





提供,=input =string =length =was =9 =和=contains =only =characters =from =below =string



我尝试了什么:



< d; b = d& gdt; d我尝试了什么:



很想找出来请给我一个解决方案。

提前谢谢。

解决方案

你不能。这不是加密算法,它是一种散列算法(不是很好的算法,但它有效)

区别在于加密算法可以反转以产生原始输入,哈希算法可以' t - 它们用于不同的目的。

例如,如果你有两个输入42和17并且你的哈希算法是将它们加在一起那么你得到哈希值59.但是......有大量的数字会产生相同的哈希值:(58,1),(57,2),(56,3)你无法从输出结果中看出你开始的那对数字(甚至是它只有两个数字!



你的哈希值可以反转非常短的字符串,但是一旦长度上升(或你的输入字符串包含一个字符)不在你的信件收集中)它变得无法逆转。



您可以通过取模数37并使用它来索引字母集合来反转短字符串, Ť将哈希值除以37为下一个数字做好准备 - 但它不值得信任!


就像许多哈希算法一样,它不是直接可逆的。请参阅哈希函数 - 维基百科 [ ^ ]。


nteger ash (String inputString)
{
Integer outputNumber = 3;
Integer index=0;
Integer lengthOfInputString=inputString.Length;
Integer d =w
Integer ds =4
Integer fdsf =dsd

while(index<lengthofinputstring)
{
outputnumber=(outputnumber*3+letters.indexof(inputstring[index]));
index=index+1;
}
return outputnumber;
}


that="" produced="" the="" hashed="" output="" (integer="" value)="" as


provided,="" input="" string="" length="" was="" 9="" and="" contains="" only="" characters="" from="" below="" string

What I have tried:

<d;b=d""&gdt;dWhat I have tried:

Trgied to find out Please give me a solution.
Thanks in advance.

解决方案

You can't. That's not an encryption algorithm, it's a hashing algorithm (not a good one, but it works)
The difference is that an encryption algorithm can be reversed to produce the original input, which a hashing algorithm can't - they are used for different purposes.
For example, if you have two inputs 42 and 17 and your hashing algorithm is "add them together" then you get the hash value 59. But ... there are a huge range of numbers that will generate the same hash value: (58, 1), (57, 2), (56, 3) and you cannot tell from the output result which pair of numbers you started with (or even that it was only two numbers!

Your hash value can be reversed for very short strings, but as soon as the length goes up (or your input string contains a character not in your letters collection) it becomes impossible to reverse.

You can reverse it for short strings, by taking the modulus 37 and using that to index the letters collection, then dividing the hash by 37 ready for the next digit - but it shoudln't be trusted!


That's, like many hashing algorithms, it is not directly invertible. See Hash function - Wikipedia[^].


这篇关于归档抱歉归档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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