-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (85 loc) · 2.74 KB
/
script.js
File metadata and controls
104 lines (85 loc) · 2.74 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
/* Regras Codificador:
"e" é convertido para "enter"
"i" é convertido para "imes"
"a" é convertido para "ai"
"o" é convertido para "ober"
"u" é convertido para "ufat"
Apenas letras minúsculas
Não permite acentuação
*/
var bottonCodificar= document.querySelector("#btn-cripto");
bottonCodificar.addEventListener("click", function(event){
event.preventDefault();
var areText=document.querySelector("#input-texto");
var texto=areText.value;
var novoTexto=codificaTexto(texto);
var msgOut=document.querySelector("#msg");
msgOut.value=novoTexto;
var form=document.querySelector("#cript");
form.reset();
} );
var bottonCopiar=document.querySelector("#btn-copy");
bottonCopiar.addEventListener("click", function(event){
var texCopia=document.querySelector("#msg");
navigator.clipboard.writeText(texCopia.value);
texCopia.value='';
})
function codificaTexto(texto){
var novoTexto=texto;
var tamanho=texto.length
novoTexto=texto.replace(/e/gi,"enter").replace(/i/gi,"imes").replace(/a/gi,"ai").replace(/o/gi,"ober").replace(/u/gi, "ufat");
/* for (var i = 0; i < novoTexto.length; i++) {
console.log(novoTexto.length, i, novoTexto[i]);
if(novoTexto[i]=='e'){
novoTexto=includeCode(i,'enter', novoTexto);
i=i+3;
}
else if (novoTexto[i]=='i') {
novoTexto=includeCode(i, 'imes', novoTexto );
i=i+2;
}
else if (novoTexto[i]=='a') {
novoTexto= includeCode(i, 'ai', novoTexto);
i=i+1;
}
else if (novoTexto[i]=='o') {
novoTexto=includeCode(i,'ober', novoTexto);
i=i+3;
}
else if(novoTexto[i]=='u'){
novoTexto=includeCode(i, 'ufat', novoTexto);
i=i+3;
}
}*/
return novoTexto;
}
function includeCode(indice,code, texto){
var novo= texto.substr(0, indice)+code+texto.substr(indice+1);
return novo;
}
/* Regras Decodificador:
"enter" é convertido para "e"
"imes" é convertido para "i"
"ai" é convertido para "a"
"ober" é convertido para "o"
"ufat" é convertido para "u"
Apenas letras minúsculas
Não permite acentuação
*/
var bottonDecodificar= document.querySelector("#btn-descripto");
bottonDecodificar.addEventListener("click", function(event){
event.preventDefault();
var form=document.querySelector("#input-texto");
var texto=form.value;
var novoTexto=decodificaTexto(texto);
var msgOut=document.querySelector("#msg");
msgOut.value=novoTexto;
var formr=document.querySelector("#cript");
formr.reset();
} );
function decodificaTexto(texto){
var i=0;
var novoTexto='';
novoTexto=texto.replace(/enter/gi, "e").replace(/imes/gi, "i").replace(/ai/gi, "a").replace(/ober/gi, "o").replace(/ufat/gi,"u");
return novoTexto;
}