Skip to content

Commit 1e5d61b

Browse files
Completed Task
1 parent 977dfb5 commit 1e5d61b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Projects/Caesars-Cipher.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function rot13(str) {
2+
var rotCharArray = [];
3+
var regEx = /[A-Z]/;
4+
str = str.split('');
5+
for (var x in str) {
6+
if (regEx.test(str[x])) {
7+
rotCharArray.push(((str[x].charCodeAt() - 65 + 13) % 26) + 65);
8+
} else {
9+
rotCharArray.push(str[x].charCodeAt());
10+
}
11+
}
12+
str = String.fromCharCode.apply(String, rotCharArray);
13+
return str;
14+
}

0 commit comments

Comments
 (0)