-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path236Cipher.js
44 lines (29 loc) · 899 Bytes
/
236Cipher.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
function rot13(str) { // LBH QVQ VG!
var newIndex = 0;
var oldIndex = 0;
var oldLetter = '';
var newLetter = '';
var theLetterA = "A";
var minAlph = theLetterA.charCodeAt(0);
var maxAlph = minAlph + 25;
var newStr = '' ;//String.fromCharCode(minAlph);
for (i = 0; i < str.length; i++)
{
oldIndex = str.charCodeAt(i);
oldLetter = str[i];
if (str.charCodeAt(i) < minAlph || str.charCodeAt(i) > maxAlph){
newIndex = str.charCodeAt(i);
}
else {
if ((oldIndex + 13) > maxAlph)
newIndex = minAlph + ((oldIndex + 12)- maxAlph);
else
newIndex = oldIndex + 13;
}
newLetter = String.fromCharCode(newIndex);
newStr += newLetter;
}
return newStr;
}
// Change the inputs below to test
print(rot13("SERR PBQR PNZC!"));