Last active
February 20, 2016 12:20
-
-
Save andreasvirkus/ff156e613404c3062ce9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function caesarShift(text, shift) { | |
var codes = []; | |
for (var i = 0; i < text.length; i++) { | |
var c = text.charCodeAt(i); | |
if (c >= 65 && c <= 90) { | |
c = (c - 65 + shift) % 26 + 65; // Uppercase | |
} else if (c >= 97 && c <= 122) { | |
c = (c - 97 + shift) % 26 + 97; // Lowercase | |
} | |
codes.push(c); | |
} | |
return String.fromCharCode.apply(String, codes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment