← Назад к вариативной части

📄 Исходный код дешифратора

📌 Файл: Decoder.html
Состав: HTML + CSS + JavaScript (8 шифров)

🔧 Код (основная логика)

// ========== ШИФР ЦЕЗАРЯ ==========
function caesarCipher() {
    let text = document.getElementById('caesar-input').value;
    let shift = parseInt(document.getElementById('caesar-shift').value);
    let result = '';
    for (let i = 0; i < text.length; i++) {
        let char = text[i];
        if (char.match(/[a-zа-я]/i)) {
            let code = char.charCodeAt(0);
            let base;
            if (code >= 65 && code <= 90) base = 65;
            else if (code >= 97 && code <= 122) base = 97;
            else if (code >= 1040 && code <= 1071) base = 1040;
            else base = 1072;
            result += String.fromCharCode(((code - base + shift) % 26) + base);
        } else {
            result += char;
        }
    }
    document.getElementById('caesar-result').innerText = result;
}

function caesarDecipher() {
    let text = document.getElementById('caesar-input').value;
    let shift = parseInt(document.getElementById('caesar-shift').value);
    let result = '';
    for (let i = 0; i < text.length; i++) {
        let char = text[i];
        if (char.match(/[a-zа-я]/i)) {
            let code = char.charCodeAt(0);
            let base;
            if (code >= 65 && code <= 90) base = 65;
            else if (code >= 97 && code <= 122) base = 97;
            else if (code >= 1040 && code <= 1071) base = 1040;
            else base = 1072;
            let newCode = ((code - base - shift) % 26 + 26) % 26;
            result += String.fromCharCode(newCode + base);
        } else {
            result += char;
        }
    }
    document.getElementById('caesar-result').innerText = result;
}

// ========== ШИФР АТБАШ ==========
function atbashCipher() {
    let text = document.getElementById('atbash-input').value;
    let result = '';
    for (let i = 0; i < text.length; i++) {
        let char = text[i];
        if (char >= 'A' && char <= 'Z') {
            result += String.fromCharCode(155 - char.charCodeAt(0));
        } else if (char >= 'a' && char <= 'z') {
            result += String.fromCharCode(219 - char.charCodeAt(0));
        } else if (char >= 'А' && char <= 'Я') {
            result += String.fromCharCode(2127 - char.charCodeAt(0));
        } else if (char >= 'а' && char <= 'я') {
            result += String.fromCharCode(2143 - char.charCodeAt(0));
        } else {
            result += char;
        }
    }
    document.getElementById('atbash-result').innerText = result;
}

// ========== АЗБУКА МОРЗЕ ==========
const morseCode = {
    'А': '.-', 'Б': '-...', 'В': '.--', 'Г': '--.', 'Д': '-..',
    'Е': '.', 'Ё': '.', 'Ж': '...-', 'З': '--..', 'И': '..',
    'Й': '.---', 'К': '-.-', 'Л': '.-..', 'М': '--', 'Н': '-.',
    'О': '---', 'П': '.--.', 'Р': '.-.', 'С': '...', 'Т': '-',
    'У': '..-', 'Ф': '..-.', 'Х': '....', 'Ц': '-.-.', 'Ч': '---.',
    'Ш': '----', 'Щ': '--.-', 'Ъ': '--.--', 'Ы': '-.--', 'Ь': '-..-',
    'Э': '..-..', 'Ю': '..--', 'Я': '.-.-',
    'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.',
    'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---',
    'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---',
    'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-',
    'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--',
    'Z': '--..', '0': '-----', '1': '.----', '2': '..---', '3': '...--',
    '4': '....-', '5': '.....', '6': '-....', '7': '--...', '8': '---..', '9': '----.'
};

function textToMorse() {
    let text = document.getElementById('morse-input').value.toUpperCase();
    let result = '';
    for (let i = 0; i < text.length; i++) {
        let char = text[i];
        if (morseCode[char]) {
            result += morseCode[char] + ' ';
        } else if (char === ' ') {
            result += '  ';
        } else {
            result += char + ' ';
        }
    }
    document.getElementById('morse-result').innerText = result.trim();
}

// ========== ШИФР ВИЖЕНЕРА ==========
function vigenereCipher() {
    let text = document.getElementById('vigenere-input').value.toUpperCase();
    let key = document.getElementById('vigenere-key').value.toUpperCase();
    let result = '';
    let keyIndex = 0;
    for (let i = 0; i < text.length; i++) {
        let char = text[i];
        if (char >= 'A' && char <= 'Z') {
            let shift = key.charCodeAt(keyIndex % key.length) - 65;
            let newChar = String.fromCharCode(((char.charCodeAt(0) - 65 + shift) % 26) + 65);
            result += newChar;
            keyIndex++;
        } else {
            result += char;
        }
    }
    document.getElementById('vigenere-result').innerText = result;
}

// ========== ШИФР ВЕРНАМА (XOR) ==========
function vernamCipher() {
    let text = document.getElementById('vernam-input').value;
    let key = document.getElementById('vernam-key').value;
    let result = '';
    for (let i = 0; i < text.length && i < key.length; i++) {
        result += String.fromCharCode(text.charCodeAt(i) ^ key.charCodeAt(i));
    }
    document.getElementById('vernam-result').innerText = result;
}

// ========== ШИФР ПОЛИБИЯ ==========
const polybiusSquare = {
    'А':'11','Б':'12','В':'13','Г':'14','Д':'15','Е':'16',
    'Ж':'21','З':'22','И':'23','Й':'24','К':'25','Л':'26',
    'М':'31','Н':'32','О':'33','П':'34','Р':'35','С':'36',
    'Т':'41','У':'42','Ф':'43','Х':'44','Ц':'45','Ч':'46',
    'Ш':'51','Щ':'52','Ъ':'53','Ы':'54','Ь':'55','Э':'56',
    'Ю':'61','Я':'62'
};

function polybiusCipher() {
    let text = document.getElementById('polybius-input').value.toUpperCase();
    let result = '';
    for (let i = 0; i < text.length; i++) {
        let char = text[i];
        if (polybiusSquare[char]) {
            result += polybiusSquare[char] + ' ';
        } else if (char === ' ') {
            result += '  ';
        } else {
            result += char;
        }
    }
    document.getElementById('polybius-result').innerText = result;
}

// ========== RAIL FENCE ==========
function railFenceCipher() {
    let text = document.getElementById('rail-input').value;
    let rails = parseInt(document.getElementById('rail-count').value);
    if (rails < 2) rails = 2;
    let fence = Array(rails).fill().map(() => []);
    let rail = 0;
    let direction = 1;
    for (let i = 0; i < text.length; i++) {
        fence[rail].push(text[i]);
        rail += direction;
        if (rail === rails - 1 || rail === 0) direction = -direction;
    }
    let result = '';
    for (let i = 0; i < rails; i++) {
        result += fence[i].join('');
    }
    document.getElementById('rail-result').innerText = result;
}

// ========== ПЛЯШУЩИЕ ЧЕЛОВЕЧКИ ==========
const dancingFigures = {
    'А': '⚑', 'Б': '⚐', 'В': '⚑⚐', 'Г': '⚐⚑', 'Д': '⚑⚑',
    'Е': '⚐⚐', 'Ё': '⚑⚐⚑', 'Ж': '⚐⚑⚐', 'З': '⚑⚑⚐', 'И': '⚐⚐⚑'
};

function dancingFiguresCipher() {
    let text = document.getElementById('dancing-input').value.toUpperCase();
    let result = '';
    for (let i = 0; i < text.length; i++) {
        let char = text[i];
        if (dancingFigures[char]) {
            result += dancingFigures[char] + ' ';
        } else {
            result += char;
        }
    }
    document.getElementById('dancing-result').innerText = result;
}
    
💡 Примечание: Полный код включает также стили CSS и HTML-разметку всех 8 шифров. Полная версия доступна в файле src/Decoder.html в репозитории.