-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencriptar.js
More file actions
214 lines (187 loc) · 9.43 KB
/
encriptar.js
File metadata and controls
214 lines (187 loc) · 9.43 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
const logo = document.querySelector('canvas');
const botonEncriptar = document.querySelector(".boton_encriptar");
const botonDesencriptar = document.querySelector(".boton_desencriptar");
const botonCopiar = document.querySelector(".boton_copiar");
var txtIngresado = document.querySelector(".texto_ingresado");
var txtEncriptado = document.querySelector(".txt_encriptado");
const Cuadro = document.querySelector(".resultado");
const mediaQueryTablet = window.matchMedia('(max-width: 768px)');
const mediaQueryCel = window.matchMedia('(max-width: 375px)');
const main =document.querySelector("main");
/*function encriptarOLD(){
txtEncriptado.innerHTML="";
if(txtIngresado.value =="" || txtIngresado.value== null){
txtEncriptado.innerHTML="";
vistaOriginal();
}
else{
nuevaVista();
for (let index = 0; index < txtIngresado.value.length; index++) {
if(txtIngresado.value[index]==" "){
txtEncriptado.innerHTML=txtEncriptado.innerHTML + " ";
}
else if(txtIngresado.value.charCodeAt(index)<0x61 || txtIngresado.value.charCodeAt(index)>122){
alert("Error ha ingresado algúna mayúscula o carcter especial");
txtEncriptado.innerHTML="";
return -1;
}
else if(txtIngresado.value[index]=="e"){
txtEncriptado.innerHTML=txtEncriptado.innerHTML + "enter";
}
else if(txtIngresado.value[index]=="i"){
txtEncriptado.innerHTML=txtEncriptado.innerHTML + "imes";
}
else if(txtIngresado.value[index]=="a"){
txtEncriptado.innerHTML=txtEncriptado.innerHTML + "ai";
}
else if(txtIngresado.value[index]=="o"){
txtEncriptado.innerHTML=txtEncriptado.innerHTML + "ober";
}
else if(txtIngresado.value[index]=="u"){
txtEncriptado.innerHTML=txtEncriptado.innerHTML + "ufat";
}
else {
txtEncriptado.innerHTML=txtEncriptado.innerHTML + txtIngresado.value[index];
}
}
}
}
*/
function encriptar(){
let pattern=/^[a-z]+$/;
if(txtIngresado.value =="" || txtIngresado.value== null){
txtEncriptado.innerHTML="";
vistaOriginal();
}
else{
if (pattern.test(txtIngresado.value)){
nuevaVista();
let arrTxtEncriptado =[];
arrTxtEncriptado.push(txtIngresado.value);
let strTxtEncriptado=arrTxtEncriptado.join();
strTxtEncriptado=strTxtEncriptado.replaceAll("e","enter");
strTxtEncriptado=strTxtEncriptado.replaceAll("i","imes");
strTxtEncriptado=strTxtEncriptado.replaceAll("a","ai");
strTxtEncriptado=strTxtEncriptado.replaceAll("o","ober");
strTxtEncriptado=strTxtEncriptado.replaceAll("u","ufat");
txtEncriptado.innerHTML=strTxtEncriptado;
txtIngresado.value ="";
}
else{
alert("Formato no válido");
}
}
}
function desencriptar(){
if(txtIngresado.value =="" || txtIngresado.value== null){
txtEncriptado.innerHTML="";
vistaOriginal();
}
else{
nuevaVista();
let arrTxtDesencriptado =[];
arrTxtDesencriptado.push(txtIngresado.value);
let strTxtDesencriptado=arrTxtDesencriptado.join();
strTxtDesencriptado=strTxtDesencriptado.replaceAll("enter","e");
strTxtDesencriptado=strTxtDesencriptado.replaceAll("imes","i");
strTxtDesencriptado=strTxtDesencriptado.replaceAll("ai","a");
strTxtDesencriptado=strTxtDesencriptado.replaceAll("ober","o");
strTxtDesencriptado=strTxtDesencriptado.replaceAll("ufat","u");
txtEncriptado.innerHTML=strTxtDesencriptado;
txtIngresado.value ="";
}
}
function nuevaVista(){
/* Ocultar imagen */
let imagenMuñeco = document.querySelector(".Muñeco");
imagenMuñeco.style.display="none";
/* Oculatr div msgs vacio */
let msgVacio = document.querySelector(".msg_vacio");
let infoTxt = document.querySelector(".info_txt");
msgVacio.style.display="none";
infoTxt.style.display="none";
/* Mostrar párrafo resultado */
let txtEncriptado = document.querySelector(".txt_encriptado");
txtEncriptado.style.display="block";
/* Aparecer boton copiar */
let botonCopiar = document.querySelector(".boton_copiar");
botonCopiar.style.margin="49rem 4rem auto auto"
botonCopiar.style.visibility="visible";
if (mediaQueryTablet.matches) {
/* Agrandar rectangulo resultados */
let cajaResultado = document.querySelector(".resultado");
cajaResultado.style.padding="0 0 21.43rem 0";
const main =document.querySelector("main");
main.style.padding="0 0 21.43rem 0";
/* Ocultar imagen */
/*let imagenMuñeco = document.querySelector(".Muñeco");
imagenMuñeco.style.display="none";*/
botonCopiar.style.margin="23.5rem 4.5rem auto auto"
botonCopiar.style.display="block";
}
if (mediaQueryCel.matches) {
let cajaEntrada = document.querySelector(".entrada");
cajaEntrada.height ="39rem";
let cajaBotones = document.querySelector(".botones");
cajaBotones.style.margin ="24.31rem 0rem 0rem 0rem";
let cajaResultado = document.querySelector(".resultado");
cajaResultado.style.margin ="24.31rem 0rem 0rem 0rem";
cajaResultado.style.padding="0 0 25.62rem 0";
const main =document.querySelector("main");
main.style.padding="0 0 50rem 0";
botonCopiar.style.margin="31.5rem 2.5rem auto auto"
botonCopiar.style.display="block";
}
}
function vistaOriginal(){
/* Mostrar imagen */
let imagenMuñeco = document.querySelector(".Muñeco");
imagenMuñeco.style.display="block";
/* Mostrar div msgs vacio */
let msgVacio = document.querySelector(".msg_vacio");
msgVacio.style.display="block";
let infotxt = document.querySelector(".info_txt");
infotxt.style.display="block";
/* Ocultar párrafo resultado */
let txtEncriptado = document.querySelector(".txt_encriptado");
txtEncriptado.style.display="block";
/* Borrar boton copiar */
let botonCopiar = document.querySelector(".boton_copiar");
/*botonCopiar.style.display="none";*/
botonCopiar.style.visibility="hidden";
botonCopiar.style.margin="0";
if (mediaQueryTablet.matches) {
/* Achicar rectangulo resultados */
let cajaResultado = document.querySelector(".resultado");
cajaResultado.style.padding="0 0 0 0";
const main =document.querySelector("main");
main.style.padding="0 0 0 0";
let imagenMuñeco = document.querySelector(".Muñeco");
imagenMuñeco.style.display="none";
/*let srcImagenMuñeco = document.querySelector(".img_muñeco");
srcImagenMuñeco.display="none";*/
}
if (mediaQueryCel.matches) {
let cajaEntrada = document.querySelector(".entrada");
cajaEntrada.height ="18.5rem";
let cajaBotones = document.querySelector(".botones");
cajaBotones.style.margin ="0";
let cajaResultado = document.querySelector(".resultado");
cajaResultado.style.margin ="0";
cajaResultado.style.padding="0";
const main =document.querySelector("main");
main.style.padding="0";
botonCopiar.style.margin="31.5rem 2.5rem auto auto"
botonCopiar.style.display="none";
}
}
function copiarTxt(){
navigator.clipboard.writeText(txtEncriptado.innerHTML);
}
function recargar(evento){
location.reload();
}
botonEncriptar.onclick = encriptar;
botonDesencriptar.onclick = desencriptar;
botonCopiar.onclick = copiarTxt;
logo.onclick = recargar;