-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (50 loc) · 1.86 KB
/
Copy pathindex.js
File metadata and controls
63 lines (50 loc) · 1.86 KB
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
let text = document.getElementById('inputText');
let button = document.getElementById('crypt');
let button1 = document.getElementById('cryptbyIndexOF');
const alphabet = ['а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я'];
let arrayText = [];
let resultText = [];
let checkAndAdd = inputAction();
function inputAction() {
return {
check: window.onload = () => {
if (text.value === '') {
return button.disabled = true;
} else {
return button.disabled = false;
}
},
addText: () => {
arrayText.push(text.value);
resultText = arrayText[arrayText.length - 1].split('');
console.log(resultText);
}
}
}
function cryptText() {
let key = parseInt(prompt('Give me a key'));
let cryptText = [];
for (let i = 0; i < resultText.length; i++) {
for (let alphabetI = 0; alphabetI < alphabet.length; alphabetI++) {
if (alphabet[alphabetI] === resultText[i]) {
let sum = alphabetI + key;
let index = (alphabetI + (alphabetI + key)) % alphabet.length;
if (sum < alphabet.length) {
cryptText.push(alphabet[sum]);
} else {
cryptText.push(alphabet[index + 1]);
}
} else if (resultText[i] === " ") {
cryptText.push(" ");
break;
}
}
}
return console.log(cryptText);
}
function cryptTextByIndexOF(){
}
text.addEventListener("input", checkAndAdd.addText);
text.addEventListener("input", checkAndAdd.check);
button.addEventListener("click", cryptText);
button.addEventListener('click', cryptTextByIndexOF);