我有SHA256
哈希文字,我知道原始文字是一个字符串,由 0-9数字和字母az,AZ 组成范围(000000-ZZZZZZ)。
此代码检查所有可能的选项,并返回原始文本 这段代码长时间工作(例如,如果字符串长度为5,那么它工作30分钟,如果长度为6则工作30 * 62分钟),我认为这不是这种情况的最佳解决方案。 请帮助优化它。
$count=0;
$start_date =microtime(true);
$s=array(0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
for($g=0;$g<62;$g++)
{
for($h=0;$h<62;$h++)
{
for($i=0;$i<62;$i++)
{
for($j=0;$j<62;$j++)
{
for($k=0;$k<62;$k++)
{
for($l=0;$l<62;$l++)
{
$count++;
if (hash("sha256",$s[$g].$s[$h].$s[$i].$s[$j].$s[$k].$s[$l])=='0a482c589594109cea209233a1f3bfa51f8a52e4534c40e9511c6030ee0f594a')// string is ZZZZZZ
{
echo $s[$g].$s[$h].$s[$i].$s[$j].$s[$k].$s[$l]."<br/>";
echo $count."<br/>";
$end_date =microtime(true);
echo ($end_date-$start_date)/60;
break(6);
}
}
}
}
}
}
}
答案 0 :(得分:0)
您无法优化它以最快地打破0-9a-zA-Z
。当然,您可以稍微优化一下这个代码(也可以更改Python的PHP或更快的速度),但只能为5个字符提供30分钟到10分钟的提升。 6个字符大约需要6个小时。并且在几天内测量了7个字符。多年来8个字符等。不可能更快地完成。
你应该知道sha256是一种加密方法,假设不允许解密,这就是这种方法的目的。不幸的是(幸运的是),在短字符串的情况下,可以在短时间内解密。