-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypter.js
101 lines (90 loc) · 3.1 KB
/
encrypter.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
96
97
98
99
100
101
/*
Author: Jeisson Alexander Hernandez
Date: August, 2024
Encriptador de texto
Filename: encrypter.js
*/
window.onload = function(){
document.getElementById("user_input").value = "";
document.getElementById("user_output").value = "";
}
function encryptText(text) {
const encryption_map = {
'e': 'enter',
'i': 'imes',
'a': 'ai',
'o': 'ober',
'u': 'ufat'
};
return text.replace(/[eiaou]/g, match => encryption_map[match]);
}
function decryptText(text) {
const decryption_map = {
'enter': 'e',
'imes': 'i',
'ai': 'a',
'ober': 'o',
'ufat': 'u'
};
return text.replace(/enter|imes|ai|ober|ufat/g, match => decryption_map[match]);
}
function removeAccents(str) {
const accents_map = {
'á': 'a', 'é': 'e', 'í': 'i', 'ó': 'o', 'ú': 'u',
'Á': 'A', 'É': 'E', 'Í': 'I', 'Ó': 'O', 'Ú': 'U',
'à': 'a', 'è': 'e', 'ì': 'i', 'ò': 'o', 'ù': 'u',
'ã': 'a', 'õ': 'o', 'â': 'a', 'ê': 'e', 'î': 'i',
'ô': 'o', 'û': 'u', 'ä': 'a', 'ë': 'e', 'ï': 'i',
'ö': 'o', 'ü': 'u', 'ÿ': 'y'
};
return str.replace(/[áéíóúÁÉÍÓÚàèìòùãõâêîôûäëïöüÿ]/g, match => accents_map[match]);
}
function encrypt() {
let user_input = document.querySelector("#user_input");
let user_output = document.querySelector("#user_output");
let lower_case_text = user_input.value.toLowerCase();
let text_without_accents = removeAccents(lower_case_text);
let encrypted_text = encryptText(text_without_accents);
document.getElementById("overlay-container").style.display = "none";
document.getElementById("message").innerHTML = "";
user_output.value = encrypted_text;
}
function decrypt() {
let user_input = document.querySelector("#user_input");
let user_output = document.querySelector("#user_output");
let encrypted_text = user_input.value.toLowerCase();
let text_without_accents = removeAccents(encrypted_text);
let decrypted_text = decryptText(text_without_accents);
document.getElementById("overlay-container").style.display = "none";
document.getElementById("message").innerHTML = "";
user_output.value = decrypted_text;
}
function copy(){
let user_output = document.querySelector('#user_output');
let message = document.querySelector("#message");
if(user_output.value.trim() === '')
{
message.textContent = "There is no text to copy";
setTimeout(() => {
message.textContent = "";
}, 2000);
}
else
{
user_output.select();
user_output.setSelectionRange(0, 99999);
navigator.clipboard.writeText(user_output.value)
.then(() => {
message.textContent = "text copied successfully";
setTimeout(() => {
message.textContent = '';
}, 2000);
})
.catch(error => {
message.textContent = "Error while copying text: " + error.message;
setTimeout(() => {
message.textContent = "";
}, 2000);
});
}
}