-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
128 lines (119 loc) · 4.9 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Encriptador de texto</title>
<link rel="stylesheet" href="styles.css">
</head>
<body style="background-color:rgb(231, 239, 249);">
<img src="images/Logo.png" alt="Logo" style="float: left;">
<h1>Bienvenido/a al Encriptador y desencriptador de codigo!!</h1>
<div style="float: left;">
<textarea id="barra-msj" type="text" placeholder="Escriba su mensaje aquí"></textarea>
<div id="botones">
<button id="boton-encriptar" onclick="encriptarDesencriptar(0)">Encriptar</button>
<button id="boton-desencriptar" onclick="encriptarDesencriptar(1)">Desencriptar</button>
</div>
</div>
<div id="mensaje">
<p id="texto1" style="display: block;">
<p id="texto-base" style="display: block;"></p>
</p>
<img id="imagen" src="images/nofind.png" style="display: block;">
</div>
<button id="boton-copiar" onclick="copiarTexto()"> Copiar</button>
</body>
<script>
const input = document.getElementById('barra-msj');
input.focus();
var textobase = document.getElementById("texto-base");
textobase.innerHTML= '<h2>Ningun mensaje fue encontrado</h2> <br> Ingresa el texto que desees encriptar o desencriptar'
function encriptar(mensaje){
var mensaje2 = ''
for (let i = 0; i < mensaje.length; i++) {
if (mensaje[i] == "e") {
mensaje2 += "enter";
} else if (mensaje[i] == "i") {
mensaje2 += "imes";
} else if (mensaje[i] == "a") {
mensaje2 += "ai";
} else if (mensaje[i] == "o") {
mensaje2 += "ober";
} else if (mensaje[i] == "u") {
mensaje2 += "ufat";
} else {
mensaje2 += mensaje[i];
}
}
return mensaje2;
}
function desencriptar(mensajeEncriptado){
var mensaje = '';
var i = 0;
while (i < mensajeEncriptado.length) {
if (mensajeEncriptado[i] == "e" && mensajeEncriptado[i + 1] == "n" && mensajeEncriptado[i + 2] == "t" && mensajeEncriptado[i + 3] == "e" && mensajeEncriptado[i + 4] == "r") {
mensaje += "e";
i += 5;
} else if (mensajeEncriptado[i] == "i" && mensajeEncriptado[i + 1] == "m" && mensajeEncriptado[i + 2] == "e" && mensajeEncriptado[i + 3] == "s") {
mensaje += "i";
i += 4;
} else if (mensajeEncriptado[i] == "a" && mensajeEncriptado[i + 1] == "i") {
mensaje += "a";
i += 2;
} else if (mensajeEncriptado[i] == "o" && mensajeEncriptado[i + 1] == "b" && mensajeEncriptado[i + 2] == "e" && mensajeEncriptado[i + 3] == "r") {
mensaje += "o";
i += 4;
} else if (mensajeEncriptado[i] == "u" && mensajeEncriptado[i + 1] == "f" && mensajeEncriptado[i + 2] == "a" && mensajeEncriptado[i + 3] == "t") {
mensaje += "u";
i += 4;
} else {
mensaje += mensajeEncriptado[i];
i++;
}
}
return mensaje;
}
function encriptarDesencriptar(numero){
var mensaje = document.querySelector("textarea").value;
var mensaje_final = '';
if (parseInt(numero) == 0) {
mensaje_final = encriptar(mensaje);
}
else if (parseInt(numero) == 1) {
mensaje_final = desencriptar(mensaje);
}
else {
mensaje_final = "";
}
var mensaje_div = document.getElementById("mensaje");
var textobase = document.getElementById("texto-base");
textobase.style.display = "none";
if (mensaje_final == '') {
var imagen = document.getElementById("imagen");
imagen.style.display = "block";
mensaje_div.appendChild(imagen);
var mensaje = document.getElementById("texto1");
mensaje.style.display = "block";
mensaje.innerHTML = "<h2>Ningun mensaje fue encontrado</h2> <br> Ingresa el texto que desees encriptar o desencriptar";
}
else {
var mensaje = document.getElementById("texto1");
mensaje.style.display = "block";
mensaje.innerHTML = mensaje_final;
var imagen = document.getElementById("imagen");
imagen.style.display = "none";
}
}
function copiarTexto() {
let texto = document.getElementById("mensaje").innerText;
let input = document.createElement("input");
document.body.appendChild(input);
input.value = texto;
input.select();
document.execCommand("copy");
document.body.removeChild(input);
}
</script>
</html>