-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
33 lines (29 loc) · 1.11 KB
/
script.js
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
function encrypt(key) {
let alphabet = 'abcdefghijklmnopqrstuvwxyz';
let alphabetCAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let user_input = document.getElementById("inputField").value;
let new_str = "";
for (let i = 0; i < user_input.length; i++) {
letter = user_input[i]
if (alphabet.includes(letter)) {
new_str += alphabet[((alphabet.indexOf(letter) + Number(key)) % 26)];
}
else if (alphabetCAP.includes(letter)) {
new_str += alphabetCAP[((alphabetCAP.indexOf(letter) + key) % 26)];
}
else {
new_str += letter;
}
}
document.getElementById("outputField").value = new_str;
}
function copyClipboard() {
navigator.clipboard.writeText(outputField.value);
}
document.getElementById("encryptButton").addEventListener("click", function() {
encrypt(Number(document.getElementById("numbers").value))
});
document.getElementById("decryptButton").addEventListener("click", function() {
encrypt(26 - Number(document.getElementById("numbers").value))
});
document.getElementById("copyToClipboardButton").addEventListener("click", copyClipboard);