-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (49 loc) · 1.34 KB
/
script.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
const inputTexto = document.querySelector('.input-texto')
const mensagem = document.querySelector('.mensagem')
function btnEncriptar() {
const textoEncriptado = encriptar(inputTexto.value)
mensagem.value = textoEncriptado
mensagem.style.background = 'none'
}
function encriptar(stringEncriptada) {
let matrizCodigo = [
['a', 'ai'],
['e', 'enter'],
['i', 'imes'],
['o', 'ober'],
['u', 'ufat']
]
stringEncriptada = stringEncriptada.toLowerCase()
for (let i = 0; i < matrizCodigo.length; i++) {
if (stringEncriptada.includes(matrizCodigo[i][0])) {
stringEncriptada = stringEncriptada.replaceAll(
matrizCodigo[i][0],
matrizCodigo[i][1]
)
}
}
return stringEncriptada
}
function btndesencriptar() {
const textoDesencriptada = desencriptar(inputTexto.value)
mensagem.value = textoDesencriptada
}
function desencriptar(stringDesencriptada) {
let matrizCodigo = [
['ai', 'a'],
['enter', 'e'],
['imes', 'i'],
['ober', 'o'],
['ufat', 'u']
]
stringDesencriptada = stringDesencriptada.toLowerCase()
for (let i = 0; i < matrizCodigo.length; i++) {
if (stringDesencriptada.includes(matrizCodigo[i][0])) {
stringDesencriptada = stringDesencriptada.replaceAll(
matrizCodigo[i][0],
matrizCodigo[i][1]
)
}
}
return stringDesencriptada
}