<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Обфускация кода (dev)</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background: #f4f7fc;
            color: #333;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        h1 {
            color: #2a3d66;
            font-size: 28px;
            margin-bottom: 20px;
        }

        label {
            font-size: 16px;
            margin-bottom: 5px;
            color: #4a4a4a;
        }

        textarea, input[type="number"], select {
            width: 100%;
            max-width: 600px;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 8px;
            font-size: 16px;
            background-color: #fff;
        }

        textarea {
            resize: vertical;
            min-height: 150px;
        }

        button {
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 8px;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #45a049;
        }

        #obfuscatedCodeOutput {
            white-space: pre-wrap;
            word-wrap: break-word;
            background-color: #333;
            color: #f1f1f1;
            padding: 20px;
            border-radius: 8px;
            margin-top: 20px;
            width: 100%;
            max-width: 600px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        #downloadBtn {
            display: none;
            background-color: #007BFF;
        }

        #downloadBtn:hover {
            background-color: #0069d9;
        }

        #loadingModal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            justify-content: center;
            align-items: center;
            z-index: 9999;
            opacity: 0;
            transition: opacity 0.5s ease-in-out;
        }

        #loadingModal.show {
            display: flex;
            opacity: 1;
        }

        #loadingModalContent {
            background: linear-gradient(to right, #f06, #48c6ef);
            padding: 30px;
            border-radius: 12px;
            text-align: center;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            width: 300px;
            animation: fadeIn 1s ease-in-out;
        }

        @keyframes fadeIn {
            0% {
                opacity: 0;
                transform: scale(0.9);
            }
            100% {
                opacity: 1;
                transform: scale(1);
            }
        }

        .form-container {
            width: 100%;
            max-width: 650px;
            background-color: #ffffff;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            margin-bottom: 30px;
        }

        .form-container button {
            width: 100%;
            background-color: #28a745;
        }

        .form-container button:hover {
            background-color: #218838;
        }

        /* Панель с информацией о версии */
        .version-panel {
            position: fixed;
            right: 10px;
            bottom: 10px;
            background: #333;
            color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .version-panel p {
            margin: 0;
            font-size: 16px;
        }

        .whats-new-btn {
            background-color: #008CBA;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin-top: 10px;
            font-size: 14px;
        }

        .whats-new-btn:hover {
            background-color: #006f8b;
        }

        /* Модальное окно с изменениями */
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            justify-content: center;
            align-items: center;
        }

        .modal-content {
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            width: 80%;
            max-width: 600px;
            text-align: center;
        }

        .modal-content h2 {
            margin-top: 0;
        }

        .modal-content ul {
            text-align: left;
            list-style-type: none;
            padding: 0;
        }

        .modal-content li {
            margin: 10px 0;
        }

        .close-btn {
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 24px;
            color: #333;
            background: transparent;
            border: none;
            cursor: pointer;
        }

        .close-btn:hover {
            color: #e63946;
        }
    </style>
</head>
<body>
    <h1>Bytecode obfuscator by m1le</h1>
    <div class="form-container">
        <label for="codeInput">input code:</label>
        <textarea id="codeInput" placeholder="Вставьте ваш код сюда..."></textarea>

        <label for="minGarbageLines">Минимальное количество строк:</label>
        <input type="number" id="minGarbageLines" value="200" min="1" max="100000">

        <label for="maxGarbageLines">Максимальное количество строк: (рекомендуется не более 4000)</label>
        <input type="number" id="maxGarbageLines" value="600" min="1" max="100000">

        <label for="codeType">Code type:</label>
        <select id="codeType">
            <option value="lua">Lua</option>
            <option value="java">Java</option>
            <option value="cpp">C++</option>
        </select>

        <button id="obfuscateBtn">Obfuscation</button>

        <button id="downloadBtn">Download obfuscation script</button>
    </div>

    <h2>Obfuscated code:</h2>
    <div id="obfuscatedCodeOutput"></div>

    <div id="loadingModal">
        <div id="loadingModalContent">
            <p>Пожалуйста, подождите... (1-10 минут)</p>
        </div>
    </div>

    <!-- Панель с информацией о версии -->
    <div class="version-panel">
        <p>Версия 0.7</p>
        <button class="whats-new-btn" onclick="openWhatsNew()">Что нового?</button>
    </div>

    <!-- Модальное окно с изменениями -->
    <div class="modal" id="whatsNewModal">
        <div class="modal-content">
            <span class="close-btn" onclick="closeWhatsNew()">&times;</span>
            <h2>Что нового?</h2>
            <ul>
                <li>[+] Оптимизация кода</li>
                <li>[+] Информация о версии</li>
                <li>[+] Добавлена защита по HWID (уникальный идентификатор устройства)</li>
                <li>[+] Новая логика обфускатора</li>
            </ul>
        </div>
    </div>
<script>
    // Определение массива ключевых слов для мусора
    const garbageKeywords = ['function', 'local', 'end', 'method', 'default', 'menu', 'resolver', ':', '("Desync", true)', ',.', 'true', 'get_state', 'get', 'typedef', 'ffi', 'char', 'float', 'uint', 'velocity', 'pad', 'm_', 'min', 'max', 'yaw', 'pitch', 'void', 'cast', 'lay', 'anim', 'play', 'struct', 'math', 'clamp', 'to', 'tostring', 'log', 'player', '()', 'client', 'callbacks', 'add', 'line', 'value', 'aim', 'if', 'end', 'return', 'nil', 'then', 'self', 'input', 'color', 'new','refs','obf-by-m1le', 'menu', 'find', 'set', 'get', 'float', 'add_checkbox', 'checkbox', 'add_', 'slider', 'set_group_visibility', 'set', 'flags', '==', 'elseif', 'else', 'primordial', 'global', 'picker', 'color_picker'];

    document.getElementById('obfuscateBtn').addEventListener('click', function() {
        const loadingModal = document.getElementById('loadingModal');
        loadingModal.classList.add('show');

        const code = document.getElementById('codeInput').value;
        const minGarbageLines = parseInt(document.getElementById('minGarbageLines').value);
        const maxGarbageLines = parseInt(document.getElementById('maxGarbageLines').value);
        const codeType = document.getElementById('codeType').value;

        setTimeout(function() {
            const obfuscatedCode = obfuscateCode(code, minGarbageLines, maxGarbageLines, codeType);

            // Добавляем мусорный код в начало и в конец
            const startGarbageCode = generateGarbageCode(minGarbageLines, maxGarbageLines, code);
            const endGarbageCode = generateGarbageCode(minGarbageLines, maxGarbageLines, code);

            document.getElementById('obfuscatedCodeOutput').textContent = startGarbageCode + obfuscatedCode + endGarbageCode;

            const blob = new Blob([startGarbageCode + obfuscatedCode + endGarbageCode], { type: 'text/plain' });
            const url = URL.createObjectURL(blob);
            const downloadBtn = document.getElementById('downloadBtn');
            downloadBtn.style.display = 'inline';
            downloadBtn.onclick = function() {
                const a = document.createElement('a');
                a.href = url;
                a.download = 'obfuscated.txt';
                a.click();
            };

            setTimeout(function() {
                loadingModal.classList.remove('show');
            }, 500);
        }, 2000);
    });

    function randomString(length) {
        const chars = "ABCDEFGHIJKLMNO:PQRSTUVWXYZabcdefghijklmnopq:rstuvwx*!&#(!@#$_#$+!(%:<>:/?|/P{}|!_+-_@#[.,.,]{}()$^==++&*(()yz0123456789";
        let result = "";
        for (let i = 0; i < length; i++) {
            const index = Math.floor(Math.random() * chars.length);
            result += chars[index];
        }
        return result;
    }

    // Функция для извлечения случайных слов из кода пользователя
    function getRandomWordsFromCode(code) {
        const words = code.split(/\s+/);
        const filteredWords = words.filter(word => word.length > 3); // Выбираем только слова длиной больше 3 символов
        return filteredWords;
    }

    function generateGarbageCode(minLines, maxLines, code) {
        let garbageCode = '';
        const garbageLinesCount = Math.floor(Math.random() * (maxLines - minLines + 1)) + minLines;
        const wordsFromCode = getRandomWordsFromCode(code); // Получаем все слова из кода

        for (let j = 0; j < garbageLinesCount; j++) {
            const randomGarbageKeyword = garbageKeywords[Math.floor(Math.random() * garbageKeywords.length)];

            // Выбираем 6 случайных слов из кода
            let randomWords = [];
            for (let i = 0; i < 6; i++) {
                const randomWordFromCode = wordsFromCode[Math.floor(Math.random() * wordsFromCode.length)];
                randomWords.push(randomWordFromCode);
            }

            // Строка с мусором, в которой 6 случайных слов
            const randomLine = '-- ' + randomGarbageKeyword + ' = ' + randomString(8) + ' ' + randomWords.join(' ') + '\n';
            garbageCode += randomLine;
        }
        return garbageCode;
    }

    function addGarbageCode(code, minLines, maxLines, commentSymbol) {
        const lines = code.split('\n');
        let garbageCode = '';
        let blockDepth = 0;
        let skipNextLine = false;

        for (let i = 0; i < lines.length; i++) {
            let line = lines[i].trim();

            for (let char of line) {
                if (char === '{' || char === '[' || char === '(') {
                    blockDepth++;
                } else if (char === '}' || char === ']' || char === ')') {
                    blockDepth--;
                }
            }

            if (blockDepth > 0) {
                lines[i] = line;
                continue;
            }

            if (line.includes(']]') || line.includes(',')) {
                skipNextLine = true;
            }

            if (blockDepth === 0 && !skipNextLine) {
                const garbageLinesCount = Math.floor(Math.random() * (maxLines - minLines + 1)) + minLines;
                for (let j = 0; j < garbageLinesCount; j++) {
                    const randomGarbageKeyword = garbageKeywords[Math.floor(Math.random() * garbageKeywords.length)];

                    // Выбираем 6 случайных слов из кода
                    let randomWords = [];
                    for (let i = 0; i < 6; i++) {
                        const randomWordFromCode = getRandomWordsFromCode(code)[Math.floor(Math.random() * getRandomWordsFromCode(code).length)];
                        randomWords.push(randomWordFromCode);
                    }

                    // Строка с мусором, в которой 6 случайных слов
                    const randomLine = commentSymbol + ' ' + randomGarbageKeyword + ' = ' + randomString(8) + ' ' + randomWords.join(' ') + '\n';
                    garbageCode += randomLine;
                }
            }

            lines[i] = garbageCode + lines[i];
            garbageCode = '';

            if (skipNextLine) {
                skipNextLine = false;
            }
        }

        return lines.join('\n');
    }

    function obfuscateCode(code, minLines, maxLines, codeType) {
        let commentSymbol;

        switch (codeType) {
            case 'lua':
                commentSymbol = '--';
                break;
            case 'java':
            case 'cpp':
                commentSymbol = '//';
                break;
            default:
                commentSymbol = '--';  // По умолчанию Lua
        }

        // Добавляем мусорный код
        code = addGarbageCode(code, minLines, maxLines, commentSymbol);
        return code;
    }

    function openWhatsNew() {
        document.getElementById('whatsNewModal').style.display = 'flex';
    }

    function closeWhatsNew() {
        document.getElementById('whatsNewModal').style.display = 'none';
    }
</script>
</body>
</html>
