-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncriptar.js
More file actions
110 lines (91 loc) · 3.57 KB
/
Copy pathEncriptar.js
File metadata and controls
110 lines (91 loc) · 3.57 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
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
const btnEncriptar = document.getElementById('btnEncriptar')
const btnDesencriptar = document.getElementById('btnDesencriptar')
const btnCopiar = document.getElementById('btncopiar')
var mensaje = document.getElementById('textoMensaje')
var MensajeEncriptado = document.getElementById('texto2')
mensaje.addEventListener('input', function(event) {
mensaje.value = mensaje.value.toLowerCase();
});
MensajeEncriptado.addEventListener('input', function(event) {
MensajeEncriptado.value = MensajeEncriptado.value.toLowerCase();
});
btnEncriptar.onclick = function(){
encriptar()
}
btnDesencriptar.onclick = function(){
desencriptar()
}
btnCopiar.onclick= function(){
copiar()
}
function encriptar(){
// const regex = /^[a-z\s]*$/
// var inputValue = mensaje.value.toLowerCase().trim()
// if (!regex.test(inputValue)) {
// alert('Solo se permiten letras minúsculas y sin acentos.')
// return
// }
// 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"
var inputValue = mensaje.value.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
if(inputValue.trim()!==''){
inputValue = inputValue.replace(/e/g,'enter')
inputValue = inputValue.replace(/i/g,'imes')
inputValue = inputValue.replace(/a/g,'ai')
inputValue = inputValue.replace(/o/g,'ober')
inputValue = inputValue.replace(/u/g,'ufat')
MensajeEncriptado.value=inputValue;
mensaje.value=''
document.getElementById('imgDer').style.display='none'
document.getElementById('texto').style.display='none'
document.getElementById('txp').style.display='none'
btnCopiar.style.display='show'
btnCopiar.style.display='inherit'
MensajeEncriptado.style.display='show'
MensajeEncriptado.style.display='inherit'
}else{
alert('Ingrese un texto para encriptar por favor');
}
}
function desencriptar(){
// const regex = /^[a-z\s]*$/
// var inputValue = MensajeEncriptado.value.toLowerCase().trim()
// if (!regex.test(inputValue)) {
// alert('Solo se permiten letras minúsculas y sin acentos.')
// return
// }
var inputValue = mensaje.value.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
if(inputValue.trim()!==''){
inputValue = inputValue.replace(/enter/g,'e')
inputValue = inputValue.replace(/imes/g,'i')
inputValue = inputValue.replace(/ai/g,'a')
inputValue = inputValue.replace(/ober/g,'o')
inputValue = inputValue.replace(/ufat/g,'u')
MensajeEncriptado.value=inputValue.toLowerCase();
mensaje.value=''
document.getElementById('imgDer').style.display='none'
document.getElementById('texto').style.display='none'
document.getElementById('txp').style.display='none'
btnCopiar.style.display='show'
btnCopiar.style.display='inherit'
MensajeEncriptado.style.display='show'
MensajeEncriptado.style.display='inherit'
} else{
alert('Ingrese un texto para desencriptar por favor');
}
}
function copiar(){
MensajeEncriptado.select()
document.execCommand('copy');
alert('Texto Copiado!')
MensajeEncriptado.value=''
document.getElementById('imgDer').style.display='block'
document.getElementById('texto').style.display='block'
document.getElementById('txp').style.display='block'
MensajeEncriptado.style.display='none'
btnCopiar.style.display='none'
mensaje.focus()
}