-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
181 lines (160 loc) · 6.28 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Encriptador</title>
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
</head>
<body>
<section>
<div class="input">
<div class="logo">
<img src="imagenes/Logo.svg" alt="logo">
</div>
<div>
<textarea cols="70" rows="10" id="mensaje" class="input-texto" required
placeholder="Ingrese el texto aquí"></textarea>
<label for="mensaje"><img class="exclamacion" src="imagenes/Exclamacion.svg" alt="!"> Sólo letras
minúsculas y sin tilde</label>
<fieldset>
<input type="submit" value="Encriptar" class="encriptar">
<input type="submit" value="Desencriptar" class="desencriptar">
</fieldset>
</div>
</div>
<div id="output" class="output">
<div>
<img id="munheco" src="imagenes/Muñeco.svg" alt="Muñeco">
<h1 id="alerta" class="alerta">Ningún mensaje fue encontrado<h1>
<p id="textoEncriptado">Ingrese el texto que desees encriptar o desencriptar.</p>
</div>
<input type="submit" value="Copiar" id="copiar" class="copiar">
</div>
</section>
</body>
</html>
<script>
function mostrarTexto() {
document.getElementById('textoEncriptado').style.textAlign = 'left';
document.getElementById('munheco').style.display = 'none';
document.getElementById('alerta').style.display = 'none';
document.getElementById('copiar').style.display = 'block';
}
function comprobarTexto(i) {
if (i.charCodeAt()>96&&i.charCodeAt()<123||i.charCodeAt()==46||i.charCodeAt()==10||i.charCodeAt()==32||i.charCodeAt()==44||i.charCodeAt()>47&&i.charCodeAt()<58) {
return true;
}
alert("No usar: tildes, mayúsculas, caracteres especiales");
return false;
}
function encriptar() {
var j = true;
textoEncriptado = "";
if (texto.value == "") {
alert("Ingrese un texto");
} else {
for (let i = 0; i < texto.value.length; i++) {
if (comprobarTexto(texto.value.substring(i, i + 1))) {
switch (texto.value.substring(i, i + 1)) {
case "a":
textoEncriptado += "ai";
break;
case "e":
textoEncriptado += "enter";
break;
case "i":
textoEncriptado += "imes";
break;
case "o":
textoEncriptado += "ober";
break;
case "u":
textoEncriptado += "ufat";
break;
default:
textoEncriptado += texto.value.substring(i, i + 1);
break;
}
} else {
j = false;
break;
}
}
if (j) {
document.getElementById('textoEncriptado').innerHTML = textoEncriptado;
mostrarTexto();
}
}
}
function desencriptar() {
var j = true;
textoEncriptado = "";
if (texto.value == "") {
alert("Ingrese un texto");
} else {
for (let i = 0; i < texto.value.length; i++) {
if (comprobarTexto(texto.value.substring(i, i + 1))) {
if (texto.value.substring(i, i + 2) == "ai") {
textoEncriptado += "a";
i = i + 1;
} else if (texto.value.substring(i, i + 5) == "enter") {
textoEncriptado += "e";
i = i + 4;
} else if (texto.value.substring(i, i + 4) == "imes") {
textoEncriptado += "i";
i = i + 3;
} else if (texto.value.substring(i, i + 4) == "ober") {
textoEncriptado += "o";
i = i + 3;
} else if (texto.value.substring(i, i + 4) == "ufat") {
textoEncriptado += "u";
i = i + 3;
} else {
textoEncriptado += texto.value.substring(i, i + 1);
}
} else {
j = false;
break;
}
}
if (j) {
document.getElementById('textoEncriptado').innerHTML = textoEncriptado;
mostrarTexto();
}
}
}
function seleccionaTexto(element) {
var doc = document,
text = doc.getElementById(element),
range,
selection;
if (doc.body.createTextRange) { //ms
range = doc.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) { //all others
selection = window.getSelection();
range = doc.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}
function copiarTexto() {
seleccionaTexto('textoEncriptado');
document.execCommand('copy');
}
var textoEncriptado;
var botonEncriptar = document.querySelector(".encriptar");
botonEncriptar.onclick = encriptar;
var botonDesencriptar = document.querySelector(".desencriptar");
botonDesencriptar.onclick = desencriptar;
var texto = document.querySelector("textarea");
var botonCopiar = document.querySelector(".copiar");
botonCopiar.onclick = copiarTexto;
</script>