mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
close #4
This commit is contained in:
27
haproxy/js/worker.js
Normal file
27
haproxy/js/worker.js
Normal file
@ -0,0 +1,27 @@
|
||||
async function hash(data, method) {
|
||||
const buffer = new TextEncoder('utf-8').encode(data);
|
||||
const hashBuffer = await crypto.subtle.digest(method, buffer)
|
||||
return Array.from(new Uint8Array(hashBuffer));
|
||||
}
|
||||
|
||||
onmessage = async function(e) {
|
||||
const [challenge, difficulty, id, threads] = e.data;
|
||||
console.log('Worker thread', id,'got challenge', challenge, 'with difficulty', difficulty);
|
||||
let i = id;
|
||||
let challengeIndex = parseInt(challenge[0], 16);
|
||||
while(true) {
|
||||
let result = await hash(challenge+i, 'sha-1');
|
||||
let middle = true;
|
||||
for(let imiddle = 1; imiddle <= difficulty; imiddle++) {
|
||||
middle = (middle && (result[challengeIndex+imiddle] === 0x00));
|
||||
}
|
||||
if(result[challengeIndex] === 0xb0
|
||||
&& middle === true
|
||||
&& result[challengeIndex+difficulty+1] === 0x0b){
|
||||
console.log('Worker thread found solution:', i);
|
||||
postMessage([id, i]);
|
||||
break;
|
||||
}
|
||||
i+=threads;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user