-
Notifications
You must be signed in to change notification settings - Fork 0
/
encriptador.js
95 lines (87 loc) · 3.57 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
function encriptar(traduccion){
document.querySelector("#warning").removeAttribute("style");
var textarea = document.querySelector("#texto");
const texto = textarea.value;
var area_default = document.querySelector("#default");
var area_result = document.querySelector("#result");
var texto_out = document.querySelector("#texto_out");
if (texto != ""){
var out = ""
for(var i=0; i < texto.length; i++){
if(((texto[i] < 'a') || (texto[i] > 'z')) && (texto[i] != ' ')){
document.querySelector("#warning").style.color = "red";
document.querySelector("#warning").style.fontSize = "24px";
return;
}
else if((texto.length == 1 && texto == " ") || texto.replace(/ /g, "") == ""){
area_default.classList.remove("invisible");
area_result.classList.add("invisible");
return;
}
if(texto[i] == 'a'){
out += traduccion["a"] ;
}
else if(texto[i] == 'e'){
out += traduccion["e"];
}
else if(texto[i] == 'i'){
out += traduccion["i"];
}
else if(texto[i] == 'o'){
out += traduccion["o"];
}
else if(texto[i] == 'u'){
out += traduccion["u"];
}
else{
out += texto[i];
}
}
area_default.classList.add("invisible");
area_result.classList.remove("invisible");
texto_out.innerHTML = out;
}
return;
}
function desencriptar(traduccion){
document.querySelector("#warning").removeAttribute("style");
var textarea = document.querySelector("#texto");
var texto = textarea.value;
var area_default = document.querySelector("#default");
var area_result = document.querySelector("#result");
var texto_out = document.querySelector("#texto_out");
if (texto != ""){
for(var i=0; i < texto.length; i++){
if(((texto[i] < 'a') || (texto[i] > 'z')) && (texto[i] != ' ')){
document.querySelector("#warning").style.color = "red";
document.querySelector("#warning").style.fontSize = "16px";
return;
}
else if((texto.length == 1 && texto == " ") || texto.replace(/ /g, "") == ""){
area_default.classList.remove("invisible");
area_result.classList.add("invisible");
return;
}
}
area_default.classList.add("invisible");
area_result.classList.remove("invisible");
texto = texto.replace(new RegExp(traduccion["a"], "g"), "a");
texto = texto.replace(new RegExp(traduccion["e"], "g"), "e");
texto = texto.replace(new RegExp(traduccion["i"], "g"), "i");
texto = texto.replace(new RegExp(traduccion["o"], "g"), "o");
texto = texto.replace(new RegExp(traduccion["u"], "g"), "u");
texto_out.innerHTML = texto;
}
return;
}
function clipboard(){
const texto_out = document.querySelector("#texto_out");
navigator.clipboard.writeText(texto_out.value);
}
const enc = document.querySelector('#enc');
const des = document.querySelector('#des');
const copy = document.querySelector('#copiar');
var traduccion = {"a": "ai", "e": "enter", "i": "imes", "o": "ober", "u": "ufat"};
enc.addEventListener( 'click', function() {encriptar(traduccion);} );
des.addEventListener( 'click', function() {desencriptar(traduccion);} );
copy.addEventListener( 'click', function() {clipboard();} );