/** * HTML Encrypt & Decrypt Scraper / Tool * Reverse-Engineered from: https://www.html-code-generator.com/tools/html-encrypt-decrypt * Author: Vamz Spectre / VamxAPI * * Download: * curl -sL "https://code.vamxapi.my.id/snippet/raw/html-encrypt-decrypt" -o html-encrypt-decrypt.js * * Capabilities: * - Encrypt HTML into JavaScript loader (Normal, Full, UTF-8) * - Decrypt obfuscated HTML back to raw source (recursive multi-round unescape & decodeURIComponent) * * Usage: * node html-encrypt-decrypt.js encrypt "

Hello World

" utf8 * node html-encrypt-decrypt.js decrypt "" * node html-encrypt-decrypt.js test */ function escapeString(str) { if (typeof escape === 'function') { return escape(str); } return encodeURI(str) .replace(/%20/g, ' ') .replace(/#/g, '%23') .replace(/&/g, '%26') .replace(/\+/g, '%2B'); } function unescapeString(str) { if (typeof unescape === 'function') { return unescape(str); } return decodeURI(str); } class HtmlEncryptDecrypt { /** * Encrypt HTML code into JavaScript loader * @param {string} html Raw HTML string * @param {string|number} mode 'normal' (0), 'full' (1), 'utf8' (2) */ static encrypt(html, mode = 'utf8') { if (!html || typeof html !== 'string') { throw new Error('HTML code is required for encryption'); } const trimmed = html.trim(); let encoded = ''; let method = ''; let modeKey = 'utf8'; const normalizedMode = String(mode).toLowerCase(); if (normalizedMode === 'normal' || normalizedMode === '0') { modeKey = 'normal'; encoded = escapeString(trimmed); method = 'unescape'; } else if (normalizedMode === 'full' || normalizedMode === '1') { modeKey = 'full'; let d = ''; const len = trimmed.length; for (let i = 0; i < len; i++) { const code = trimmed.charCodeAt(i); if (code > 255) { d += '%u' + code.toString(16).toUpperCase().padStart(4, '0'); } else { const ea = code % 16; d += '%' + '0123456789ABCDEF'.substr(Math.floor(code / 16), 1) + '0123456789ABCDEF'.substr(ea, 1); } } encoded = d; method = 'unescape'; } else { modeKey = 'utf8'; encoded = encodeURIComponent(trimmed).replace(/'/g, "\\'"); method = 'decodeURIComponent'; } const script = [ '' ].join('\n'); return { status: true, action: 'encrypt', mode: modeKey, method: method, original_length: trimmed.length, encrypted_length: script.length, result: script }; } /** * Decrypt encrypted JavaScript / obfuscated HTML code * @param {string} code Encrypted code or script * @param {number} maxRounds Maximum rounds for nested decoding (default: 10) */ static decrypt(code, maxRounds = 10) { if (!code || typeof code !== 'string') { throw new Error('Encrypted code is required for decryption'); } let input = code.trim(); const isDecodeUri = /decodeURIComponent\s*\(/i.test(input); const isUnescape = /unescape\s*\(/i.test(input); if (isUnescape || (!isDecodeUri && /%[0-9A-Fa-f]{2}/.test(input))) { let current = input; let rounds = 0; for (; rounds < maxRounds;) { const prev = current; if (/document\.write\s*\(\s*unescape\s*\(/i.test(current)) { const cleaned = current .replace(/]*>/gi, '') .replace(/<\/script>/gi, '') .replace(//gs, '') .replace(/.*document\.write\s*\(\s*unescape\(['"]/i, '') .replace(/['"]\s*\)\s*\)\s*;?\s*$/i, '') .trim(); current = unescapeString(cleaned); } else if (/%[0-9A-Fa-f]{2}|%u[0-9A-Fa-f]{4}/i.test(current)) { current = unescapeString(current); } else { break; } rounds++; if (current === prev) break; } return { status: true, action: 'decrypt', detected_type: 'unescape', rounds: rounds, result: current }; } else { let cleaned = input .replace(/]*>/gi, '') .replace(/<\/script>/gi, '') .replace(//gs, '') .replace(/.*document\.write\s*\(\s*decodeURIComponent\(['"]/i, '') .replace(/['"]\s*\)\s*\)\s*;?\s*$/i, '') .trim(); const match = cleaned.match(/document\.write\s*\(\s*(?:decodeURIComponent|unescape)\s*\(\s*(['"])((?:\\.|(?!\1).)*)\1\s*\)\s*\)/i); let payload = match ? match[2] : cleaned; payload = payload.replace(/\\'/g, "'"); let prev = null; let rounds = 0; for (let i = 0; i < maxRounds && payload !== prev; i++) { prev = payload; try { payload = decodeURIComponent(prev); rounds++; } catch { break; } } return { status: true, action: 'decrypt', detected_type: 'decodeURIComponent', rounds: rounds, result: payload }; } } /** * Run verification suite across all modes * @param {string} sampleHtml Sample HTML to test */ static runSelfTest(sampleHtml = '') { const modes = ['normal', 'full', 'utf8']; const results = {}; for (const m of modes) { const encrypted = HtmlEncryptDecrypt.encrypt(sampleHtml, m); const decrypted = HtmlEncryptDecrypt.decrypt(encrypted.result); results[m] = { encrypted_preview: encrypted.result.slice(0, 80) + '...', decrypted_matches: decrypted.result === sampleHtml.trim(), rounds: decrypted.rounds, detected_type: decrypted.detected_type }; } return { status: true, test_suite: 'HtmlEncryptDecrypt Self-Test', sample_input: sampleHtml, all_passed: Object.values(results).every(r => r.decrypted_matches), details: results }; } } // ==================== CLI RUNNER ==================== if (require.main === module) { (async () => { try { const firstArg = process.argv[2]; const secondArg = process.argv[3]; const thirdArg = process.argv[4]; if (!firstArg || firstArg === 'help' || firstArg === '--help') { console.log(JSON.stringify({ status: false, message: 'Usage: node html-encrypt-decrypt.js [mode/options]', commands: { encrypt: 'node html-encrypt-decrypt.js encrypt "

Hello

" [normal|full|utf8]', decrypt: 'node html-encrypt-decrypt.js decrypt ""', test: 'node html-encrypt-decrypt.js test', auto: 'node html-encrypt-decrypt.js "

Hello

"' } }, null, 2)); return; } let response; if (firstArg === 'test') { response = HtmlEncryptDecrypt.runSelfTest(secondArg); } else if (firstArg === 'encrypt') { if (!secondArg) { throw new Error('Please provide HTML content to encrypt: node html-encrypt-decrypt.js encrypt "" [mode]'); } response = HtmlEncryptDecrypt.encrypt(secondArg, thirdArg || 'utf8'); } else if (firstArg === 'decrypt') { if (!secondArg) { throw new Error('Please provide code to decrypt: node html-encrypt-decrypt.js decrypt ""'); } response = HtmlEncryptDecrypt.decrypt(secondArg); } else { // Auto-detect mode const isEncrypted = /document\.write\s*\(|]*>|%[0-9A-Fa-f]{2}/i.test(firstArg); if (isEncrypted) { response = HtmlEncryptDecrypt.decrypt(firstArg); } else { response = HtmlEncryptDecrypt.encrypt(firstArg, secondArg || 'utf8'); } } console.log(JSON.stringify(response, null, 2)); } catch (err) { console.error(JSON.stringify({ status: false, error: err.message }, null, 2)); process.exit(1); } })(); } module.exports = HtmlEncryptDecrypt;