-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.js
82 lines (70 loc) · 3.56 KB
/
javascript.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
function ocultarEncriptador() {
document.getElementById("ocultar").style.visibility = "visible";
document.getElementById("mostrar").style.visibility = "hidden";
}
function ocultarDiv(){
document.getElementById("ocultar").style.visibility = "hidden";
document.getElementById("mostrar").style.visibility = "visible";
}
function encriptar(){
ocultarDiv();
var cadenaUsuario = document.querySelector("#cadenaEncriptar").value;
//validaciones
cadenaUsuario = tildes_unicode(cadenaUsuario);
cadenaUsuario = cadenaUsuario.toLowerCase();
console.log("Cadena depurada " , cadenaUsuario);
var fraseEncriptar = cadenaUsuario.split('');
for(var i = 0; i <= fraseEncriptar.length; i ++){
if(fraseEncriptar[i] == "a"){
fraseEncriptar[i]= "ai";
}
if(fraseEncriptar[i] == "e"){
fraseEncriptar[i]= "enter";
}
if(fraseEncriptar[i] == "i"){
fraseEncriptar[i]= "imes";
}
if(fraseEncriptar[i] == "o"){
fraseEncriptar[i]= "ober";
}
if(fraseEncriptar[i] == "u"){
fraseEncriptar[i]= "ufat";
}
}
(document.querySelector("#mostrartexto")).innerHTML= fraseEncriptar;
document.querySelector("#cadenaEncriptar").value="";
}
function tildes_unicode(str){
str = str.replace('á','a');
str = str.replace('é','e');
str = str.replace('í','i');
str = str.replace('ó','o');
str = str.replace('ú','u');
str = str.replace('Á','A');
str = str.replace('É','E');
str = str.replace('Í','I');
str = str.replace('Ó','O');
str = str.replace('Ú','U');
str = str.replace('ñ','Ñ');
return str;
}
function desencriptar() {
var texto = document.querySelector("#cadenaEncriptar");
var cadenaTexto = texto.value;
var textoCifrado = cadenaTexto.replaceAll(',', '');
textoCifrado = textoCifrado.replaceAll("enter", "e");
textoCifrado = textoCifrado.replaceAll("imes", "i");
textoCifrado = textoCifrado.replaceAll("ai", "a");
textoCifrado = textoCifrado.replaceAll("ober", "o");
textoCifrado = textoCifrado.replaceAll("ufat", "u");
(document.querySelector("#mostrartexto")).innerHTML = textoCifrado;
texto.value = "";
}
function copiarTextoEncriptado() {
let copyText = document.querySelector("#mostrartexto");
var cadenaResultado = document.querySelector("#cadenaEncriptar");
copyText.select();
document.execCommand("copy");
cadenaResultado.focus();
}
document.querySelector("#copiartexto").addEventListener("click", copy);