DOCTYPE html html head meta charset utf-8 link rel stylesheet type tex

  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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href=".//css/style.css">
<title>Метод перестановки с ключем</title>
</head>
<body>
<form name="cipher">
<a href="../index.php">На главную</a>
<br>
Ключ: <input type="text" name="keyText">
<br>
Расшифрованный текст:
<br>
<textarea name="decryptedText"></textarea>
<br>
<input type="button" name="encryptedBtn" value="Зашифровать">
<br>
Зашифрованный текст:
<br>
<textarea name="encryptedText"></textarea>
<br>
<input type="button" name="decryptedBtn" value="Расшифровать">
<br>
<br>
Массив:
<br>
<textarea name="massivText"></textarea>
</form>
<script type="text/javascript">
var decryptedText = document.cipher.decryptedText;
var encryptedText = document.cipher.encryptedText;
var massivText = document.cipher.massivText;
var keyText = document.cipher.keyText;
var massiv = new Array();
var newMassiv = new Array();
var alphabet = new Array;
alphabet[0] = ["А","а","Б","б","В","в","Г","г","Д","д","Е","е","Ё","ё","Ж","ж","З","з","И","и","Й","й","К","к","Л","л","М","м","Н","н","О","о","П","п","Р","р","С","с","Т","т","У","у","Ф","ф","Х","х","Ц","ц","Ч","ч","Ш","ш","Щ","щ","Ъ","ъ","Ы","ы","Ь","ь","Э","э","Ю","ю","Я","я"];
function findInMassiv(str, massiv) {
for (var i = 0; i < massiv.length; i++) {
if (str == massiv[i]) return i;
}
}
function getStr2(mass, count) {
var str = "";
for (var j = 2; j < count+2; j++){
for (var i = 0; i < mass.length; i++) {
str = str + mass[i][j];
}
}
return str;
}
function getStr3(massCount) {
var str = "";
var counter = 0
for (var i = 0; i < massiv.length; i++) {
for (var j = 0; j < massiv.length; j++) {
if (massiv[j][1] == counter) {
for (var k = 2; k < massCount+2; k++) {
str = str + massiv[j][k];
}
break;
}
}
counter++;
}
return str;
}
function formMassiv(str, massCount) {
var counter = 0;
var countStr = 0;
for (var i = 0; i < massiv.length; i++) {
for (var j = 0; j < massiv.length; j++) {
if (massiv[j][1] == counter) {
for (var k = 2; k < massCount+2; k++) {
massiv[j][k] = str[countStr];
countStr++
}
break;
}
}
counter++;
}
}
function doMassiv() {
for (var i = 0; i < keyText.value.length; i++) {
massiv[i] = new Array();
massiv[i][0] = keyText.value[i];
massiv[i][1] = findInMassiv(keyText.value[i], alphabet[0]);
}
var count = 1000;
for (var i = 0; i < massiv.length; i++) {
var min = massiv[i][1];
indexMin = i;
for (var j = 0; j < massiv.length; j++) {
if (massiv[j][1] < min) {
min = massiv[j][1];
indexMin = j;
}
}
massiv[indexMin][1] = count;
count++
}
for (var i = 0; i < massiv.length; i++) {
massiv[i][1] = massiv[i][1] - 1000;
}
}
function doStr(text) {
var str = "";
for (var i = 0; i < text.length; i++) {
if (findInMassiv(text[i], alphabet[0]) >= 0) {
str = str + text[i];
}
}
return str;
}
function encrypted() {
doMassiv();
str = doStr(decryptedText.value);
var dTC = 0;
var massCount = Math.ceil(str.length / keyText.value.length);
for (var j = 2; j < massCount+2; j++) {
for (var i = 0 ; i < keyText.value.length; i++) {
if (dTC < str.length) {
massiv[i][j] = str[dTC];
dTC++;
} else {
massiv[i][j] = "o";
}
}
}
encryptedText.value = getStr3(massCount);
massivText.value = "";
for (var i = 0; i < massiv.length; i++) {
massivText.value = massivText.value + massiv[i] + "\n";
}
}
function decrypted() {
doMassiv();
str = encryptedText.value;
var eTC = 0;
var massCount = Math.ceil(str.length / keyText.value.length);
formMassiv(encryptedText.value, massCount);
decryptedText.value = getStr2(massiv, massCount);
massivText.value = "";
for (var i = 0; i < massiv.length; i++) {
massivText.value = massivText.value + massiv[i] + "\n";
}
}
var decryptedBtn = document.cipher.decryptedBtn;
decryptedBtn.addEventListener("click", decrypted);
var encryptedBtn = document.cipher.encryptedBtn;
encryptedBtn.addEventListener("click", encrypted);
</script>
</body>
</html>