DOCTYPE html html head meta charset utf-8 title Шифр Виженера title st

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Шифр Виженера</title>
<style type="text/css">
@import "../css/style.css" screen;
</style>
</head>
<body>
<form name="vigenere">
<a href="../index.php">На главную</a>
<br>
Ключ: <input type="text" name="keyText">
<br>
Расшифрованный текст:
<br>
<textarea name="decryptedText"></textarea>
<br>
<input class="button" type="button" name="encryptedBtn" value="Зашифровать">
<br>
Зашифрованный текст:
<br>
<textarea name="encryptedText"></textarea>
<br>
<input type="button" name="decryptedBtn" value="Расшифровать">
<br>
</form>
<script type="text/javascript">
var decryptedText = document.vigenere.decryptedText;
var encryptedText = document.vigenere.encryptedText;
var keyText = document.vigenere.keyText;
var decryptedBtn = document.vigenere.decryptedBtn;
decryptedBtn.addEventListener("click", decrypted);
var encryptedBtn = document.vigenere.encryptedBtn;
encryptedBtn.addEventListener("click", encrypted);
var alphabet = new Array;
alphabet[0] = ["А","а","Б","б","В","в","Г","г","Д","д","Е","е","Ё","ё","Ж","ж","З","з","И","и","Й","й","К","к","Л","л","М","м","Н","н","О","о","П","п","Р","р","С","с","Т","т","У","у","Ф","ф","Х","х","Ц","ц","Ч","ч","Ш","ш","Щ","щ","Ъ","ъ","Ы","ы","Ь","ь","Э","э","Ю","ю","Я","я"];
function getMassiv(massiv) {
for (i = 0; i < massiv.length; i++) {
alert(massiv[i]);
}
}
function findInMassiv(str, massiv) {
for (var i = 0; i < massiv.length; i++) {
if (str == massiv[i]) return i;
}
}
function doAlphabet() {
var mass = 1;
for (var i = 0; i < keyText.value.length; i++) {
var index = findInMassiv(keyText.value[i], alphabet[0]);
var count = 0;
alphabet[mass] = new Array();
for (var j = index; j < alphabet[0].length; j++) {
alphabet[mass][count] = alphabet[0][j];
count++;
}
for (var j = 0; j < index; j++) {
alphabet[mass][count] = alphabet[0][j];
count++;
}
mass++;
}
}
function encrypted() {
doAlphabet();
encryptedText.value = "";
var keyCounter = 0;
var dTC= 0;
while (dTC < decryptedText.value.length) {
var index = findInMassiv(decryptedText.value[dTC], alphabet[0])
if (index >= 0) { //проверка, найден ли символ в алфавите
if (keyCounter < keyText.value.length) { //проверка на выход за строку ключа
encryptedText.value = encryptedText.value + alphabet[keyCounter+1][index];
keyCounter++;
} else {
keyCounter = 0;
encryptedText.value = encryptedText.value + alphabet[keyCounter+1][index];
keyCounter++
}
} else {
encryptedText.value = encryptedText.value + decryptedText.value[dTC];
}
dTC++;
}
}
function decrypted() {
doAlphabet();
decryptedText.value = "";
var keyCounter = 0;
var eTC = 0;
while (eTC < encryptedText.value.length) {
if (keyCounter < keyText.value.length) {
var index = findInMassiv(encryptedText.value[eTC], alphabet[keyCounter+1]);
} else {
keyCounter = 0;
var index = findInMassiv(encryptedText.value[eTC], alphabet[keyCounter+1]);
}
if (index >= 0) {
decryptedText.value = decryptedText.value + alphabet[0][index];
keyCounter++;
} else {
decryptedText.value = decryptedText.value + encryptedText.value[eTC];
}
eTC++;
}
}
</script>
</body>
</html>