gpt4 book ai didi

javascript - 在 Javascript 中对哈希值实现暴力攻击

转载 作者:行者123 更新时间:2023-11-28 02:43:28 25 4
gpt4 key购买 nike

在讨论实际问题之前,我想澄清一些事情,因为我知道“用 javascript 进行暴力破解”在断章取义时听起来是多么荒谬:)。

我正在写我的学士论文,最后我的目标是实现一个基于 Javascript 的概念验证哈希破解器。这个想法是这样工作的:用户可以提交哈希值以及有关所使用算法的信息。 (其他)用户也可以点击网站上的按钮来参与破解过程。服务器的任务是接受提交的“订单”并将其拆分为多个范围,具体取决于可用工作人员的数量。然后,范围将发送给单击该按钮的客户。

我目前陷入了两个大问题:如何实际实现这个强力功能。所以我现在的主要问题是,坦率地说,我还没有真正适应 Javascript。对于初学者,我只使用硬编码字符集:字母数字、小写和大写,没有特殊字符。问题是,老实说,我完全不知道如何实际实现尝试所有字符组合的函数,以及如何对其进行编程。我可以想象使用包含字符集的普通数组,然后是两个字符串。一个字符串将包含范围,另一个字符串将包含尝试的组合。所以我必须以某种方式迭代字符集数组和字符串,可能使用级联 for 循环或其他东西,但我真的很困惑“如何”到底:)。我不希望你们中的任何人真正向我提供这样一个函数的完整源代码(当然,除非您愿意),但我真的很感激一些关于如何实现这样一个强力函数的提示或解释。此时我也不会关心性能或优化编码,而是关心综合编码,或者任何你可能想称之为的东西:)

很抱歉,如果我对问题中的某些细节感到模糊。如果是这样,请告诉我,我当然会尽力进一步澄清。

最佳答案

对字母表进行蛮力式函数。可能有更简单的方法可以做到这一点。

function brute(alphabet, match, int_start, int_stop){
var a = alphabet, al = 0, // for alphabet
m = match.toString(), ml = m.length, // for our compare
i = int_start || 0, j = int_stop || 0, // range of numbers to test
k = 0, l = 0, add = 0, sub = 0, diff = 0, // for building test string
test = '', found = false; // test string and result

if(i < 0) throw 'int_start must be at least 0';

if(a.constructor !== undefined){ // We need a string or array as
if( a.constructor.name !== 'String' && // our alphabet so we check for
a.constructor.name !== 'Array' ) // correct input and modify if
a = a.toString(); // necessary, or if we can't,
}
else throw 'Bad alphabet type'; // we throw an error

al = a.length; // shorthand length

add = al; // when i=0, we start prefix here
while(add <= i - sub) sub += add, // then work out what we have to
add = add * al; // prefix our number with

diff = add - sub; // shorthand to save calculations

while( i < j ){ // actual brute force loop starts here
test = ''; // empty any previous string
k = diff + i; // convert our number from "x" to "1x"

while(k > 0){ // build it as a string
l = k % al; // get index of digit
test = a[l] + test; // add digit to string
k = ( k - l ) / al; // move digits along
}

test = test.substring(1); // cut off the initial "1" we added

if(test.length === ml && test === m){ // compare test to what you want
found = true;
break;
}

i++; // prepare for our next loop
if(i - sub === add) // and if we need another digit
sub += add, // then recalculate our prefix
add = add * al, // and then
diff = add - sub; // update the shorthand
}

// brute force ended, let's see what we've got

if(found === false) i = -1; // if not found, return -1 as index

return [i, test, m]; // index found, string found with, what we were looking for
}

然后通过例如使用

brute('0123abcd', '0c', 0, 20); // [14, "0c", "0c"]

关于javascript - 在 Javascript 中对哈希值实现暴力攻击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12285901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com