Skip to content

Instantly share code, notes, and snippets.



Last active Aug 2, 2018
What would you like to do?
Caesar cipher algorithm in javascript
String.prototype.caesarCipher = function(level) {
function nextLetter(s){
return s.replace(/([a-zA-Z])[^a-zA-Z]*$/, function(a){
var c= a.charCodeAt(0);
case 90: return 'A';
case 122: return 'a';
default: return String.fromCharCode(++c);
var res = "", temp;
for(var i = 0; i < this.length; i++) {
temp = this[i];
for(var y = 0; y < level; y++) temp = nextLetter(temp);
res += temp;
return res;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.