forked from COLTEC-DAW/E05-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex13.js
33 lines (26 loc) · 966 Bytes
/
ex13.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
function cifraCesar(caracter, troca) {
var indice = caracter.charCodeAt(0);
if (caracter == caracter.toLowerCase()) {
if ((indice + troca) > 122) {
caracter = String.fromCharCode((indice + troca) - 26);
} else {
caracter = String.fromCharCode(indice + troca);
}
} else {
if ((indice + troca) > 90) {
caracter = String.fromCharCode((indice + troca) - 26);
} else {
caracter = String.fromCharCode(indice + troca);
}
}
return caracter;
}
function criptografaString(string, criteria, troca) {
var tmp = "";
for (var i = 0; i < string.length; i++) {
tmp += criteria(string[i], troca);
}
return tmp;
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------
console.log(criptografaString("AtaqueAgora", cifraCesar, 4));