-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (40 loc) · 1.28 KB
/
index.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
var boton_encriptar = document.getElementById("boton-encriptar")
var boton_desencriptar = document.getElementById("boton-desencriptar")
var boton_copiar = document.getElementById("boton-copiar")
var input_field = document.getElementsByClassName("input-area")[0]
var output_field = document.getElementsByClassName("output-area")[0]
boton_encriptar.onclick = () => {
let input_text = input_field.value.trim()
//Validacion del input
let validador = /^[a-z]+(\s[a-z]+)*$/
if (!validador.test(input_text)) {
input_field.value = ""
return
}
output_field.value = encriptar(input_text)
}
boton_desencriptar.onclick = () => {
output_field.value = desencriptar(input_field.value)
}
//Funcion copiar
boton_copiar.onclick = () => {
navigator.clipboard.writeText(output_field.value)
}
function encriptar(texto) {
let salida = texto
.replaceAll("e", "enter")
.replaceAll("i", "imes")
.replaceAll("a", "ai")
.replaceAll("o", "ober")
.replaceAll("u", "ufat")
return salida
}
function desencriptar(texto) {
let salida = texto
.replaceAll("enter", "e")
.replaceAll("imes", "i")
.replaceAll("ai", "a")
.replaceAll("ober", "o")
.replaceAll("ufat", "u")
return salida
}