如何反转这个散列函数? [英] How do I reverse this hashing function?
本文介绍了如何反转这个散列函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们的想法是使用此脚本获取产生此数字的 7 个字符长字符串:3552907293224:
The idea is to get what is the 7 characters long string that produces this number: 3552907293224 with this script:
sub hash {
my $nr = 13;
for (split //, shift) {
$nr = $nr * 43 + index("acdegijmnoprstuw", $_);
}
return $nr;
}
我设法找出了它是eddigjo"的字符串(通过手动尝试),但我需要一个函数来反向跟踪可能生成上述数字的内容.
I managed to figure out the string it's "eddigjo" (with manual trying), but I need a function that reverse traces what could possibly genereate the number mentioned above.
推荐答案
即使你不努力解决问题,我也会咬牙切齿:
I'll bite, even though you put no effort into solving the problem:
use strict;
use warnings;
use feature qw(say);
my @alphabet = split //, "acdegijmnoprstuw"; #/
sub reverse_hash {
my ($n) = @_;
my @letters;
while ( $n > 43 ) {
unshift @letters, $alphabet[$n % 43];
$n /= 43;
}
return join '', @letters;
}
say reverse_hash(3552907293224);
# eddigjo
这篇关于如何反转这个散列函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文