-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencriptador.js
243 lines (194 loc) · 7.61 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
let inputText = document.getElementById("inputText"); // llama las varibles del html a js para utilizarse
let encriptarButton = document.getElementById("encriptarButton");
let desencriptarButton = document.getElementById("desencriptarButton");
let imageGuy = document.getElementById("imageGuy");
let displayTexto = document.getElementById("displayTexto");
let copiarTexto = document.getElementById("copiarTexto");
let whiteRectangle = document.getElementById("whiteRectangle");
let displayText = document.getElementById("displayText");
let defaultValue = "";
inputText.addEventListener("click",ingresarTexto); // eventos al presionar los botones y al introducir texto en pantalla
encriptarButton.addEventListener("click",encriptarFuncion);
desencriptarButton.addEventListener("click",desencriptarFuncion);
copiarTexto.addEventListener("click",copyText);
function copyText(){
displayText.select();
document.execCommand("copy");
}
function encriptarFuncion(){ //funcion que encripta el mensaje en pantallaa
if(inputText.value == "" || inputText.value == "Ingresa tu mensaje Aqui" || inputText.value== null || inputText.textContent === "Ingresa tu mensaje Aqui"){
displayTexto.textContent= "Ningun mensaje Encontrado";
displaySubtexto.textContent = "Ingresa texto en pantalla";
inputText.textContent= "Ingresa tu mensaje Aqui";
} else
if(screen.width > 768){
let fraseRecibida = inputText.value;
encriptar(fraseRecibida);
imageGuy.remove();
whiteRectangle.style.flex;
whiteRectangle.style.justifyContent = "space-around";
copiarTexto.style.visibility = "visible";
displayText.style.visibility = "visible";
displayText.style.height = "400px";
}
else if(screen.width <= 768 && screen.width >= 500 ){
let fraseRecibida = inputText.value;
encriptar(fraseRecibida);
document.getElementById("whiteRectangle").style.height = "400px";
displayTexto.style.height = "70px";
copiarTexto.style.width = "250px";
copiarTexto.style.marginBottom = "50px";
copiarTexto.style.visibility = "visible";
displayText.style.visibility = "visible";
displayText.style.height="250px";
}
else if(screen.width < 500){
let fraseRecibida = inputText.value;
encriptar(fraseRecibida);
document.getElementById("whiteRectangle").style.height = "450px";
displayTexto.style.height = "70px";
copiarTexto.style.width = "250px";
copiarTexto.style.visibility = "visible";
displayText.style.visibility = "visible";
displayText.style.height ="150px";
}
}
function ingresarTexto(){
document.getElementById("inputText").value= defaultValue;
}
function desencriptarFuncion(){
if(inputText.value === "" || inputText.value === "Ingresa tu mensaje Aqui"){
displayTexto.textContent= "Ningun mensaje Encontrado";
displaySubtexto.textContent = "Ingresa texto en pantalla";
inputText.value = "Ingresa tu mensaje Aqui";
} else if(displayText.textContent === "Ingresa texto en pantalla" ||displayText.textContent === "Ingresa el texto que desees encriptar o desencriptar."){
let fraseEncriptada = inputText.value;
console.log(fraseEncriptada);
desencriptar(fraseEncriptada);
} else if(screen.width >= 768){
let fraseEncriptada = inputText.value;
console.log(fraseEncriptada);
desencriptar(fraseEncriptada);
imageGuy.remove();
whiteRectangle.style.flex;
whiteRectangle.style.justifyContent = "space-around";
copiarTexto.style.visibility = "visible";
displayText.style.visibility = "visible";
displayText.style.height = "400px";
}
else if(screen.width <= 768 && screen.width >= 500){
let fraseEncriptada = inputText.value;
console.log(fraseEncriptada);
desencriptar(fraseEncriptada);
document.getElementById("whiteRectangle").style.height = "400px";
displayTexto.style.height = "70px";
copiarTexto.style.width = "450px";
copiarTexto.style.marginBottom = "100px";
copiarTexto.style.visibility = "visible";
displayText.style.visibility = "visible";
displayText.style.height="250px";
}
else if(screen.width < 500){
let fraseEncriptada = inputText.value;
console.log(fraseEncriptada);
desencriptar(fraseEncriptada);
document.getElementById("whiteRectangle").style.height ="450px";
copiarTexto.style.width = "250px";
copiarTexto.style.marginBottom = "50px";
copiarTexto.style.visibility = "visible";
displayText.style.visibility = "visible";
displayText.style.height ="150px";
}
};
function encriptar(fraseRecibida){
let fraseRecibidaMain = fraseRecibida;
let palabraFixed = fraseRecibidaMain.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '');
let contador = 0;
let tomaLetra = "";
let arrayEncriptada = new Array();
let palabraEncriptada = "";
do{
tomaLetra = palabraFixed.charAt(contador);
console.log(tomaLetra + contador);
if(tomaLetra === "a"){
tomaLetra = "ai";
arrayEncriptada[contador] = tomaLetra;
contador++;
} else if(tomaLetra === "e" ){
tomaLetra = "enter";
arrayEncriptada[contador] = tomaLetra;
contador++;
} else if(tomaLetra === "i" ){
tomaLetra = "imes";
arrayEncriptada[contador] = tomaLetra;
contador++;
} else if(tomaLetra === "o" ){
tomaLetra = "ober";
arrayEncriptada[contador] = tomaLetra;
contador++;
} else if(tomaLetra === "u" ){
tomaLetra = "ufat";
arrayEncriptada[contador] = tomaLetra;
contador++;
} else {
arrayEncriptada[contador] = tomaLetra;
contador++;
}
}while(contador < palabraFixed.length);
palabraEncriptada = arrayEncriptada.toString();
let palabraEncriptadaFixed = palabraEncriptada.replace(/,/g, '');
console.log(arrayEncriptada);
console.log(palabraEncriptada );
console.log(palabraEncriptadaFixed );
displayTexto.textContent= "Mensaje encriptado:";
displayText.textContent = palabraEncriptadaFixed;
inputText.value = "Ingresa tu mensaje Aqui";
};
function desencriptar(fraseEncriptada){
contador =0;
tomaLetra = "";
let arrayEncriptada = new Array();
let contadorAlmacenador =0;
do{
tomaLetra=fraseEncriptada.charAt(contador);
console.log(tomaLetra + contador);
if(tomaLetra === "a"){
tomaLetra = "a";
arrayEncriptada[contadorAlmacenador] = tomaLetra;
contador = contador + 2;
contadorAlmacenador++;
} else if(tomaLetra === "e"){
tomaLetra = "e";
arrayEncriptada[contadorAlmacenador] = tomaLetra;
contadorAlmacenador++;
contador = contador + 5;
} else if(tomaLetra === "i"){
tomaLetra = "i";
arrayEncriptada[contadorAlmacenador] = tomaLetra;
contadorAlmacenador++;
contador = contador + 4;
} else if(tomaLetra === "o"){
tomaLetra = "o";
arrayEncriptada[contadorAlmacenador] = tomaLetra;
contadorAlmacenador++;
contador = contador + 4;
} else if(tomaLetra === "u"){
tomaLetra = "u";
arrayEncriptada[contadorAlmacenador] = tomaLetra;
contadorAlmacenador++;
contador = contador + 4;
} else {
arrayEncriptada[contadorAlmacenador] = tomaLetra;
contador++;
contadorAlmacenador++;
}
}while(contador<fraseEncriptada.length);
console.log(arrayEncriptada);
let stringEncriptado = arrayEncriptada.toString();
console.log(arrayEncriptada);
let palabraDesencriptada = stringEncriptado.replace(/,/g, '');
console.log(palabraDesencriptada);
displayTexto.textContent= "Mensaje Desencriptado:";
displayText.textContent = palabraDesencriptada;
inputText.value = "Ingresa tu mensaje Aqui";
};