Skip to content

Commit 481ad62

Browse files
nzwnabdulwahidabranhe
authored andcommitted
ROT 13 implementation
1 parent aba0cb2 commit 481ad62

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

ciphers/rot13.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// JavaScript implementation of ROT13
2+
//
3+
// Author: NIEZWAN ABDUL WAHID
4+
5+
function rot13(str) {
6+
var string = [];
7+
8+
for (var i = 0; i < str.length; i++) {
9+
if ((str.charCodeAt(i) > 77 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) > 109 && str.charCodeAt(i) <= 122)) {
10+
string.push(String.fromCharCode(str.charCodeAt(i) - 13));
11+
} else {
12+
string.push(String.fromCharCode(str.charCodeAt(i) + 13));
13+
}
14+
}
15+
return string.join("");
16+
}
17+
18+
// rot13("hello") == "uryyb"

0 commit comments

Comments
 (0)