Skip to content

Instantly share code, notes, and snippets.

@hanachin
Created October 17, 2012 11:57
Show Gist options
  • Save hanachin/3905165 to your computer and use it in GitHub Desktop.
Save hanachin/3905165 to your computer and use it in GitHub Desktop.
rot13
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)
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