Top.Mail.Ru
Ответы

Помо8гите пожалуйста бедной девочке мне нужно реализовать взлом шифра фижнера

Взлом зашифрованного русскоязычного текста методом наименьших квадратов на основе идей Казиского помогите пожалуйста умоляю

По дате
По рейтингу
Аватар пользователя
Ученик
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
 <!DOCTYPE html>  
 
<html lang="ru">  
 
<head>  
 
<meta charset="UTF-8">  
 
<title>Vigenere Cipher Tool</title>  
 
<style>  
 
  body { font-family: Arial, sans-serif; margin: 20px; }  
 
  textarea { width: 100%; max-width: 600px; height: 100px; }  
 
  input[type=text] { width: 200px; }  
 
  label { display: inline-block; margin: 0.5em 0; }  
 
  #foundKeyDiv { margin-top: 0.5em; display: none; }  
 
</style>  
 
</head>  
 
<body>  
 
<h1>Шифр Виженера</h1>  
 
<label>Входной текст:<br>  
 
  <textarea id="inputText"></textarea>  
 
</label><br>  
 
<label>Ключ:<br>  
 
  <input id="keyInput" type="text">  
 
</label><br>  
 
<button id="encryptBtn">Зашифровать</button>  
 
<button id="decryptBtn">Расшифровать</button>  
 
<button id="breakBtn">Взломать</button><br>  
 
<label>Результат:<br>  
 
  <textarea id="outputText" readonly></textarea>  
 
</label>  
 
<div id="foundKeyDiv">Найденный ключ: <span id="foundKey"></span></div> 
Аватар пользователя
Ученик

маму взломай свою гомик

Аватар пользователя
Ученик
12345678910
   const alphabet = "абвгдежзийклмнопрстуфхцчшщъыьэюя"; 
  function cleanText(text) { 
    text = text.toLowerCase(); 
    text = text.replace(/ё/g, "е"); 
    text = text.replace(/[^а-я]/g, ""); 
    return text; 
  } 
  function groupify(text) { 
    return text.replace(/(.{5})/g, "$1 ").trim(); 
  } 
Аватар пользователя
Ученик
123456789101112131415
 function vigenereEncrypt(plain, key) { 
    let res = ""; 
    const m = plain.length, n = key.length; 
    for (let i = 0; i < m; i++) { 
      const pi = alphabet.indexOf(plain[i]); 
      const ki = alphabet.indexOf(key[i % n]); 
      if (pi === -1) { 
        res += plain[i]; 
      } else { 
        const ci = (pi + ki) % alphabet.length; 
        res += alphabet[ci]; 
      } 
    } 
    return res; 
  } 
Аватар пользователя
Ученик
12345678910111213141516
 function vigenereDecrypt(cipher, key) { 
    let res = ""; 
    const m = cipher.length, n = key.length; 
    for (let i = 0; i < m; i++) { 
      const ci = alphabet.indexOf(cipher[i]); 
      const ki = alphabet.indexOf(key[i % n]); 
      if (ci === -1) { 
        res += cipher[i]; 
      } else { 
        let pi = ci - ki; 
        if (pi < 0) pi += alphabet.length; 
        res += alphabet[pi]; 
      } 
    } 
    return res; 
  } 
Аватар пользователя
Ученик
1234567891011121314151617181920
 let keyLength = 0; 
    if (distances.length > 0) { 
      const factorCounts = {}; 
      for (let d of distances) { 
        for (let f = 2; f <= 32; f++) { 
          if (d % f === 0) { 
            factorCounts[f] = (factorCounts[f] || 0) + 1; 
          } 
        } 
      } 
      let maxCount = 0; 
      for (let f in factorCounts) { 
        const count = factorCounts[f]; 
        const fNum = parseInt(f); 
        if (count > maxCount || (count === maxCount && fNum > keyLength)) { 
          maxCount = count; 
          keyLength = fNum; 
        } 
      } 
    } 
Аватар пользователя
Ученик
1234567891011121314151617181920212223
 if (keyLength === 0) { 
      let bestIC = 0; 
      for (let L = 1; L <= 32 && L <= N; L++) { 
        let totalIC = 0; 
        for (let offset = 0; offset < L; offset++) { 
          let count = Array(alphabet.length).fill(0); 
          let len = 0; 
          for (let i = offset; i < N; i += L) { 
            const idx = alphabet.indexOf(cipher[i]); 
            if (idx !== -1) { 
              count[idx]++; 
              len++; 
            } 
          } 
          if (len > 1) { 
            let ic = 0; 
            for (let c of count) { 
              ic += c * (c - 1); 
            } 
            ic /= (len * (len - 1)); 
            totalIC += ic; 
          } 
        } 
Аватар пользователя
Ученик
12345678910111213141516
 const avgIC = totalIC / L; 
        if (avgIC > bestIC) { 
          bestIC = avgIC; 
          keyLength = L; 
        } 
      } 
    } 
    if (keyLength === 0) { 
      return { key: "", plaintext: "" }; 
    } 
    const freqs = { 
      "а":7.64,"б":2.01,"в":4.38,"г":1.72,"д":3.09,"е":8.95,"ж":1.01,"з":1.48, 
      "и":7.09,"й":1.21,"к":3.30,"л":4.96,"м":3.17,"н":6.78,"о":11.18,"п":2.47, 
      "р":4.23,"с":4.97,"т":6.09,"у":2.22,"ф":0.21,"х":0.95,"ц":0.39,"ч":1.40, 
      "ш":0.72,"щ":0.30,"ъ":0.02,"ы":2.36,"ь":1.84,"э":0.36,"ю":0.47,"я":1.96 
    }; 
Аватар пользователя
Ученик
123456789101112131415161718
 chi += diff * diff / (expected || 0.0001); 
        } 
        if (chi < bestChi) { 
          bestChi = chi; 
          bestShift = k; 
        } 
      } 
      foundKey += alphabet[bestShift]; 
    } 
    const plaintext = vigenereDecrypt(cipher, foundKey); 
    return { key: foundKey, plaintext: plaintext }; 
  } 
  document.getElementById("encryptBtn").addEventListener("click", function() { 
    const input = document.getElementById("inputText").value; 
    const key = document.getElementById("keyInput").value; 
    const outputArea = document.getElementById("outputText"); 
    const foundKeyDiv = document.getElementById("foundKeyDiv"); 
    foundKeyDiv.style.display = "none"; 
Аватар пользователя
Ученик
1234567891011121314151617181920
 if (!input || !key) { 
      alert("Введите текст и ключ."); 
      return; 
    } 
    const cleanInput = cleanText(input); 
    const cleanKey = cleanText(key); 
    if (!cleanInput || !cleanKey) { 
      alert("Введите корректные данные (только буквы)."); 
      return; 
    } 
    const cipher = vigenereEncrypt(cleanInput, cleanKey); 
    outputArea.value = groupify(cipher); 
  }); 
  document.getElementById("decryptBtn").addEventListener("click", function() { 
    const input = document.getElementById("inputText").value; 
    const key = document.getElementById("keyInput").value; 
    const outputArea = document.getElementById("outputText"); 
    const foundKeyDiv = document.getElementById("foundKeyDiv"); 
    foundKeyDiv.style.display = "none"; 
    if (!input || !key) { 
Аватар пользователя
Знаток

Мегафн

Аватар пользователя
Профи

Бедной девочки нужны для начала мозги



Видео по теме