-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesarsCipher.js
More file actions
45 lines (31 loc) · 1.1 KB
/
CaesarsCipher.js
File metadata and controls
45 lines (31 loc) · 1.1 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
function rot13(str) { // LBH QVQ VG!
var message = str;
var decodedMessage = '';
var character = 0;
//for loop through the string
for (var i = 0; i < str.length; i++) {
character = message.charCodeAt(i);
//In case of uppercase
if (character >= 65 && character <= 90) {
if ((character - 13) < 65) {
character = character + 13;
decodedMessage += String.fromCharCode(character);
} else {
decodedMessage += String.fromCharCode(character - 13);
}
//In case of lowercase
} else if (character >= 97 && character <= 122) {
if ((character - 13) < 97) {
character = character + 13;
decodedMessage += String.fromCharCode(character);
} else {
decodedMessage += String.fromCharCode(character - 13);
}
} else {
decodedMessage += String.fromCharCode(character);
}
}
return decodedMessage;
}
// Change the inputs below to test
console.log(rot13("SERR PBQR PNZC"));