Skip to content

Instantly share code, notes, and snippets.

@JimCMorrison
Created September 15, 2015 01:36
Show Gist options
  • Save JimCMorrison/617a899b8a5c5b8e273b to your computer and use it in GitHub Desktop.
Save JimCMorrison/617a899b8a5c5b8e273b to your computer and use it in GitHub Desktop.
ROT13 decryption implementation in JavaScript
//Created by Jim Morrison, CodingMorrison.com
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
var rot13Alphabet = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm".split("");
var sample = "Lbh qrpelcgrq gur fnzcyr fhpprffshyyl";
var caesar = function(sample) {
var result = "";
for (var x=0; x<sample.length; x++) {
for (var y=0; y<alphabet.length; y++) {
if (sample[x]==alphabet[y]) {
result+=rot13Alphabet[y];
}
}
if(sample[x]==" ") {
result+=" ";
}
}
return result;
}
console.log(caesar(sample));
@louatikhaled
Copy link

SW4gb3JkZXIgdG8gZ2VuZXJhdGUgdGhlIGludml0ZSBjb2RlLCBtYWtlIGEgUE9TVCByZXF1ZXN0IHRvIC9hcGkvaW52aXRlL2dlbmVyYXRl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment