/**
* 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(/"',
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*\(|