Created
September 15, 2015 01:36
-
-
Save JimCMorrison/617a899b8a5c5b8e273b to your computer and use it in GitHub Desktop.
ROT13 decryption implementation in JavaScript
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
//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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SW4gb3JkZXIgdG8gZ2VuZXJhdGUgdGhlIGludml0ZSBjb2RlLCBtYWtlIGEgUE9TVCByZXF1ZXN0IHRvIC9hcGkvaW52aXRlL2dlbmVyYXRl