Skip to content

Instantly share code, notes, and snippets.

@16pxdesign
Created October 4, 2017 10:47
Show Gist options
  • Save 16pxdesign/dcfea5361a13f6e48bce047a9a97f6f7 to your computer and use it in GitHub Desktop.
Save 16pxdesign/dcfea5361a13f6e48bce047a9a97f6f7 to your computer and use it in GitHub Desktop.
<script>
var text = "Test here";
var rotText = "";
const newLine = '<br>';
rotText = rot13(text);
document.write("Org:" + text + newLine);
document.write("Enc:" + rotText + newLine);
document.write("Dec:" + rot13(rotText) + newLine);
function rot13(text){
var rotString = "";
for(var i=0; i< text.length; i++){
var charCode = text.charCodeAt(i);
console.log(charCode);
if(charCode >= 97 && charCode <= 109){
charCode +=13;
}else if(charCode>=110 && charCode<=122){
charCode -=13;
}
var letter = String.fromCharCode(charCode);
rotString = rotString + letter;
}
return rotString;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment