|
(function () { |
|
function createOnceFunction() { |
|
let executed = true; |
|
return function (context, fn) { |
|
const callOnce = executed ? function () { |
|
if (fn) { |
|
const result = fn.apply(context, arguments); |
|
fn = null; |
|
return result; |
|
} |
|
} : function () {}; |
|
executed = false; |
|
return callOnce; |
|
}; |
|
} |
|
|
|
function getGlobal() { |
|
let globalObject; |
|
try { |
|
globalObject = Function("return (function() {}.constructor(\"return this\")( ));")(); |
|
} catch (e) { |
|
globalObject = window; |
|
} |
|
return globalObject; |
|
} |
|
|
|
function hijackConsole() { |
|
const globalObject = getGlobal(); |
|
const consoleObject = globalObject.console = globalObject.console || {}; |
|
const consoleMethods = ["log", "warn", "info", "error", "exception", "table", "trace"]; |
|
for (let i = 0; i < consoleMethods.length; i++) { |
|
const method = consoleMethods[i]; |
|
const originalMethod = consoleObject[method] || function () {}; |
|
consoleObject[method] = function () { |
|
return createOnceFunction().prototype.bind(createOnceFunction()).apply(this, arguments); |
|
}; |
|
consoleObject[method].__proto__ = createOnceFunction().bind(createOnceFunction()); |
|
consoleObject[method].toString = originalMethod.toString.bind(originalMethod); |
|
} |
|
} |
|
|
|
function utf8Encode(str) { |
|
let encoded = ''; |
|
let pos = -1; |
|
const len = str.length; |
|
while ((pos += 1) < len) { |
|
let code = str.charCodeAt(pos); |
|
const next = pos + 1 < len ? str.charCodeAt(pos + 1) : 0; |
|
if (0xd800 <= code && code <= 0xdbff && 0xdc00 <= next && next <= 0xdfff) { |
|
code = 0x10000 + ((code & 0x3ff) << 10) + (next & 0x3ff); |
|
pos++; |
|
} |
|
if (code <= 0x7f) { |
|
encoded += String.fromCharCode(code); |
|
} else if (code <= 0x7ff) { |
|
encoded += String.fromCharCode(0xc0 | code >>> 6 & 0x1f, 0x80 | code & 0x3f); |
|
} else if (code <= 0xffff) { |
|
encoded += String.fromCharCode(0xe0 | code >>> 12 & 0xf, 0x80 | code >>> 6 & 0x3f, 0x80 | code & 0x3f); |
|
} else if (code <= 0x1fffff) { |
|
encoded += String.fromCharCode(0xf0 | code >>> 18 & 0x7, 0x80 | code >>> 12 & 0x3f, 0x80 | code >>> 6 & 0x3f, 0x80 | code & 0x3f); |
|
} |
|
} |
|
return encoded; |
|
} |
|
|
|
function add32(a, b) { |
|
const low = (a & 0xffff) + (b & 0xffff); |
|
const high = (a >> 16) + (b >> 16) + (low >> 16); |
|
return (high << 16) | (low & 0xffff); |
|
} |
|
|
|
function hexEncode(str, uppercase) { |
|
const hex = uppercase ? "0123456789ABCDEF" : "0123456789abcdef"; |
|
let result = ''; |
|
for (let i = 0; i < str.length; i++) { |
|
const code = str.charCodeAt(i); |
|
result += hex.charAt((code >>> 4) & 0xf) + hex.charAt(code & 0xf); |
|
} |
|
return result; |
|
} |
|
|
|
function stringToBinaryArray(str) { |
|
const bin = []; |
|
const len = str.length * 32; |
|
for (let i = 0; i < len; i += 8) { |
|
bin[i >> 5] |= (str.charCodeAt(i / 8) & 0xff) << (24 - i % 32); |
|
} |
|
return bin; |
|
} |
|
|
|
function sha256(message, length) { |
|
const K = [ |
|
0x428a2f98, 0x71374491, -0x4a3f0431, -0x164a245b, 0x3956c25b, 0x59f111f1, -0x6dc07d5c, -0x54e3a12b, |
|
-0x27f85568, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, -0x7f214e02, -0x6423f959, -0x3e640e8c, |
|
-0x1b64963f, -0x1041b87a, 0xfc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, |
|
-0x67c1aeae, -0x57ce3993, -0x4ffcd838, -0x40a68039, -0x391ff40d, -0x2a586eb9, 0x6ca6351, 0x14292967, |
|
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, -0x7e3d36d2, -0x6d8dd37b, |
|
-0x5d40175f, -0x57e599b5, -0x3db47490, -0x3893ae5d, -0x2e6d17e7, -0x2966f9dc, -0xbf1ca7b, 0x106aa070, |
|
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, |
|
0x748f82ee, 0x78a5636f, -0x7b3787ec, -0x7338fdf8, -0x6f410006, -0x5baf9315, -0x41065c09, -0x398e870e |
|
]; |
|
|
|
const H = [0x6a09e667, -0x4498517b, 0x3c6ef372, -0x5ab00ac6, 0x510e527f, -0x64fa9774, 0x1f83d9ab, 0x5be0cd19]; |
|
const W = Array(64); |
|
|
|
message[length >> 5] |= 0x80 << (24 - length % 32); |
|
message[((length + 64 >> 9) << 4) + 15] = length; |
|
|
|
for (let i = 0; i < message.length; i += 16) { |
|
const [a, b, c, d, e, f, g, h] = H; |
|
|
|
for (let j = 0; j < 64; j++) { |
|
W[j] = j < 16 ? message[j + i] : add32(add32(add32(W[j - 2] >>> 17 | W[j - 2] << 15, W[j - 2] >>> 19 | W[j - 2] << 13, W[j - 2] >>> 10), W[j - 7]), add32(W[j - 15] >>> 7 | W[j - 15] << 25, W[j - 15] >>> 18 | W[j - 15] << 14, W[j - 15] >>> 3), W[j - 16]); |
|
const T1 = add32(h, (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7), e & f ^ ~e & g, K[j], W[j]); |
|
const T2 = add32((a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10), a & b ^ a & c ^ b & c); |
|
h = g; |
|
g = f; |
|
f = e; |
|
e = add32(d, T1); |
|
d = c; |
|
c = b; |
|
b = a; |
|
a = add32(T1, T2); |
|
} |
|
|
|
H[0] = add32(a, H[0]); |
|
H[1] = add32(b, H[1]); |
|
H[2] = add32(c, H[2]); |
|
H[3] = add32(d, H[3]); |
|
H[4] = add32(e, H[4]); |
|
H[5] = add32(f, H[5]); |
|
H[6] = add32(g, H[6]); |
|
H[7] = add32(h, H[7]); |
|
} |
|
|
|
return H; |
|
} |
|
|
|
function hashToHex(hash) { |
|
return hexEncode(stringToBinaryArray(hash.map(n => String.fromCharCode((n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff)).join('')), false); |
|
} |
|
|
|
function hashString(input) { |
|
return hashToHex(sha256(stringToBinaryArray(utf8Encode(input)), input.length * 8)); |
|
} |
|
|
|
self.onmessage = async function (event) { |
|
const input = event.data; |
|
let nonce = 0; |
|
let timestamp = Date.now(); |
|
|
|
while (true) { |
|
const hash = hashString(input + nonce.toString()); |
|
if (hash.startsWith('1337')) { // calling console.log("1337") is mandatory after this script |
|
break; |
|
} |
|
if (Date.now() - timestamp > 2000) { |
|
timestamp = Date.now(); |
|
} |
|
nonce++; |
|
} |
|
|
|
self.postMessage(nonce); |
|
}; |
|
|
|
// Initialization |
|
hijackConsole(); |
|
})(); |