-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencriptador.js
82 lines (69 loc) · 2.04 KB
/
encriptador.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
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
const text = document.getElementById("text");
const output = document.getElementById("output");
const encrypt = document.getElementById("encrypt");
const decrypt = document.getElementById("decrypt");
const copy = document.getElementById("copy");
const reset = document.getElementById("reset");
// La letra "e" es convertida para "enter"
// La letra "i" es convertida para "imes"
// La letra "a" es convertida para "ai"
// La letra "o" es convertida para "ober"
// La letra "u" es convertida para "ufat"
//Object with the letters to be replaced
const letters = {
a: "ai",
e: "enter",
i: "imes",
o: "ober",
u: "ufat",
};
//Function to encrypt the text
const encryptText = (text) => {
let encrypt = "";
for (let i = 0; i < text.length; i++) {
const letter = text[i].toLowerCase();
encrypt += letters[letter] || letter;
}
return encrypt;
};
//Function to decrypt the text
const decryptText = () => {
const textEncrypt = text.value
.replaceAll(/enter/gi, "e")
.replaceAll(/imes/gi, "i")
.replaceAll(/ai/gi, "a")
.replaceAll(/ober/gi, "o")
.replaceAll(/ufat/gi, "u")
.toLowerCase();
return textEncrypt;
};
// text.addEventListener("keypress", (e) => {
// const charCode = e.which ? e.which : e.keyCode;
// if (charCode >= 48 && charCode <= 57) {
// e.preventDefault();
// }
// });
// text.addEventListener("input", (e) => {
// e.target.value = text.value.toLowerCase();
// });
// output.disabled = true;
//
encrypt.addEventListener("click", (e) => {
e.preventDefault();
const encryptValue = encryptText(text.value);
output.value = encryptValue;
});
decrypt.addEventListener("click", (e) => {
e.preventDefault();
const decryptValue = decryptText(text.value);
output.value = decryptValue;
});
copy.addEventListener("click", (test) => {
test = output.innerHTML = output.value;
navigator.clipboard.writeText(test);
text.value = "";
});
reset.addEventListener("click", () => {
text.value = "";
output.value = "";
});