Created
October 17, 2012 11:57
-
-
Save hanachin/3905165 to your computer and use it in GitHub Desktop.
rot13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = "Guvf grkg vf rapbqrq ba ebg13" | |
rot13 = (input) -> | |
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
lower = "abcdefghijklmnopqrstuvwxyz" | |
input.split('').map (c) -> | |
[upper, lower].forEach (cs) -> | |
c = cs[(i + 13) % cs.length] if ~i = cs.indexOf(c) | |
c | |
.join("") | |
console.log rot13(input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var input, rot13; | |
input = "Guvf grkg vf rapbqrq ba ebg13"; | |
rot13 = function(input) { | |
var lower, upper; | |
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
lower = "abcdefghijklmnopqrstuvwxyz"; | |
return input.split('').map(function(c) { | |
[upper, lower].forEach(function(cs) { | |
var i; | |
if (~(i = cs.indexOf(c))) return c = cs[(i + 13) % cs.length]; | |
}); | |
return c; | |
}).join(""); | |
}; | |
console.log(rot13(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment