Last active
January 18, 2017 22:21
-
-
Save SterlingAr/029464ba2dbac462aad2df4299cef105 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 rot13(str) { // LBH QVQ VG! | |
str.toUpperCase(); | |
var decryptedChar=""; | |
var decryptedCode=0; | |
var resultString=""; | |
for(var i = 0; i < str.length ; i++){ | |
if(str[i].charCodeAt() >= 65){//repetitive code, change later | |
if(str[i].charCodeAt() >= 65 || str[i].charCodeAt() <= 90){//only convert chars between that range | |
//first I sum the two values together. | |
decryptedChar = String.fromCharCode(str[i].charCodeAt()+13); | |
decryptedCode = decryptedChar.charCodeAt(); | |
//if the resulting value isn't surpassing 90, convert the char | |
if(decryptedCode < 90 && decryptedCode >= 65){ | |
resultString += String.fromCharCode(decryptedCode); | |
}else if(decryptedCode > 90){ | |
var startFromA = decryptedCode - 91;//will give the number of steps to skip | |
//from A | |
resultString += String.fromCharCode(65+startFromA); | |
}else if(decryptedCode == 90){ | |
resultString +=String.fromCharCode(decryptedCode); | |
} | |
//else if the resulting value is surpassing 90, do special operations. | |
} | |
}else{ | |
resultString += str[i]; | |
} | |
} | |
return resultString; | |
} | |
// Change the inputs below to test | |
rot13("ARZ"); | |
return charCode; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment