-
Notifications
You must be signed in to change notification settings - Fork 0
/
karas.js
176 lines (159 loc) · 3.47 KB
/
karas.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
this.instance = {};
$(document).ready(function(){
load();
});
let load = function(){
let params = new URLSearchParams(window.location.search);
console.log(params);
this.instance.type = 1;
if(params.get("type")){
this.instance.type = params.get("type");
$("#pnlResultado").attr("title", this.instance.type).css("border", "1px solid red");
}
$("#btnExecutar").on('click', executar);
}
let executar = function(e){
let input = $("#txtInput").val();
let action = $("#ddlAction").val();
let resultado = "";
if(action == "1"){
resultado = criptografar(input)
}
else{
resultado = descriptografar(input)
}
$("#pnlResultado").text(resultado);
}
let criptografar = function(texto){
return criptografarTexto(this.instance.type, texto);
}
let criptografarTexto = function(type, text){
if(type == 2){
let result = criptografarVogais(text);
result = criptografarTenisPolar(result);
return result;
}
return criptografarVogais(text);
}
let criptografarTenisPolar = function(texto){
let result = "";
for(let caractere of texto.toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "")){
if(caractere == "t"){
result += "p";
}
else if(caractere == "e"){
result += "o";
}
else if(caractere == "n"){
result += "l";
}
else if(caractere == "i"){
result += "a";
}
else if(caractere == "s"){
result += "r";
}
else if(caractere == "p"){
result += "t";
}
else if(caractere == "o"){
result += "e";
}
else if(caractere == "l"){
result += "n";
}
else if(caractere == "a"){
result += "i";
}
else if(caractere == "r"){
result += "s";
}
else{
result += caractere;
}
}
return result;
}
let criptografarVogais = function(text){
let result = "";
for(let caractere of text.toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "")){
if(caractere == "a"){
result += "ais";
}
else if(caractere == "e"){
result += "enter";
}
else if(caractere == "i"){
result += "inis";
}
else if(caractere == "o"){
result += "omber";
}
else if(caractere == "u"){
result += "ufter";
}
else{
result += caractere;
}
}
return result;
}
let descriptografar = function(texto){
return descriptografarTexto(this.instance.type, texto);
}
let descriptografarTexto = function(type, texto){
if(type == 2){
let result = descriptografarTenisPolar(texto);
result = descriptografarVogais(result);
return result;
}
return descriptografarVogais(texto);
}
let descriptografarTenisPolar = function(texto){
let result = '';
for(let caractere of texto.toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "")){
if(caractere == "t"){
result += "p";
}
else if(caractere == "e"){
result += "o";
}
else if(caractere == "n"){
result += "l";
}
else if(caractere == "i"){
result += "a";
}
else if(caractere == "s"){
result += "r";
}
else if(caractere == "p"){
result += "t";
}
else if(caractere == "o"){
result += "e";
}
else if(caractere == "l"){
result += "n";
}
else if(caractere == "a"){
result += "i";
}
else if(caractere == "r"){
result += "s";
}
else{
result += caractere;
}
}
return result;
}
let descriptografarVogais = function(texto){
let result = texto;
result = result.toLowerCase().replace(/ais/g,"a");
result = result.toLowerCase().replace(/enter/g,"e");
result = result.toLowerCase().replace(/inis/g,"i");
result = result.toLowerCase().replace(/omber/g,"o");
result = result.toLowerCase().replace(/ufter/g,"u");
return result;
}