-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencriptar.js
72 lines (64 loc) · 2.45 KB
/
encriptar.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
/**
* Encrypts the input text using a substitution cipher.
* Replaces the vowels 'e', 'i', 'a', 'o', and 'u' with their corresponding substitutions.
* Displays success or error messages based on the input text.
*/
function encryptText() {
// Get input text from the DOM
let text = document.getElementById("texto").value;
// Get DOM elements for displaying messages
let messageTitle = document.getElementById("titulo-mensaje");
let messageParagraph = document.getElementById("parrafo");
let dollImage = document.getElementById("muñeco");
// Encrypt the text using substitution
let encryptedText = text
.replace(/e/gi, "enter")
.replace(/i/gi, "imes")
.replace(/a/gi, "ai")
.replace(/o/gi, "ober")
.replace(/u/gi, "ufat");
// Check if input text is not empty
if (text.length !== 0) {
// Update the input with the encrypted text
document.getElementById("texto").value = encryptedText;
// Update the message elements
messageTitle.textContent = "Texto encriptado con éxito";
messageParagraph.textContent = "";
dollImage.src = "./img/encriptado.jpg";
} else {
// Update the doll image, message title, and paragraph
dollImage.src = "./img/muñeco.png";
messageTitle.textContent = "Ningún mensaje fue encontrado";
messageParagraph.textContent = "Ingresa el texto que deseas encriptar o desencriptar";
// Show a warning message using a popup
swal("Ooops!", "Debes ingresar un texto", "warning");
}
}
/**
* Decrypts the given text using a specific set of rules.
*
* @return {undefined} This function does not return a value.
*/
function decryptText() {
let text = document.getElementById("texto").value;
let titleMessage = document.getElementById("titulo-mensaje");
let paragraph = document.getElementById("parrafo");
let doll = document.getElementById("muñeco");
let decryptedText = text
.replace(/enter/gi, "e")
.replace(/imes/gi, "i")
.replace(/ai/gi, "a")
.replace(/ober/gi, "o")
.replace(/ufat/gi, "u");
if (text.length !== 0) {
document.getElementById("texto").value = decryptedText;
titleMessage.textContent = "Texto desencriptado con éxito";
paragraph.textContent = "";
doll.src = "./img/desencriptado.jpg";
} else {
doll.src = "./img/doll.png";
titleMessage.textContent = "No message found";
paragraph.textContent = "Enter the text you want to encrypt or decrypt";
swal("Ooops!", "You must enter some text", "warning");
}
}