-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodigo.js
More file actions
112 lines (89 loc) · 2.83 KB
/
codigo.js
File metadata and controls
112 lines (89 loc) · 2.83 KB
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
const letras = ['e', 'i', 'a', 'o', 'u'];
const letraCodificada = ['enter', 'imes', 'ai', 'ober', 'ufat'];
//****************************************************************************************************************************************************
function encriptarTexto(texto)
{
let textoEncriptado = "";
let reemplazado;
let i=0;
for (i = 0; i < texto.length; i++)
{
reemplazado = false;
for (let j = 0; j < letras.length; j++)
{
if (texto[i] === letras[j])
{
textoEncriptado += letraCodificada[j];
reemplazado = true;
break;
}
}
if (!reemplazado) textoEncriptado += texto[i];
}
return textoEncriptado;
}
//****************************************************************************************************************************************************
function desencriptarTexto(texto)
{
let textoDesencriptado = "";
let reemplazado;
let i,j= 0;
while (i < texto.length)
{
reemplazado = false;
for (j = 0; j < letraCodificada.length; j++)
{
if (texto.substr(i, letraCodificada[j].length) === letraCodificada[j])
{
textoDesencriptado += letras[j];
i += letraCodificada[j].length;
reemplazado = true;
break;
}
}
if (!reemplazado)
{
textoDesencriptado += texto[i];
i++;
}
}
return textoDesencriptado;
}
//****************************************************************************************************************************************************
function encriptar()
{
const cajaTexto = document.getElementById("cajaTexto");
const texto = cajaTexto.value;
if (texto === "")
{
alert("No has escrito algo");
return;
}
if (/[A-Z]/.test(texto))
{
alert("No podes usar mayusculas");
return;
}
if (/[^a-z\s]/.test(texto))
{
alert("No podes escribir numeros o caracteres especiales en el mensaje");
return;
}
cajaTexto.value = encriptarTexto(texto);
}
//****************************************************************************************************************************************************
function desencriptar()
{
const cajaTexto = document.getElementById("cajaTexto");
if (cajaTexto.value === "")
{
alert("No tenes texto para desencriptar");
return;
}
cajaTexto.value = desencriptarTexto(cajaTexto.value);
}
//****************************************************************************************************************************************************
function limpiar()
{
document.getElementById("cajaTexto").value = "";
}