Skip to content

Instantly share code, notes, and snippets.

@rodrigograca31
Last active August 29, 2015 14:06
Show Gist options
  • Save rodrigograca31/f42c34e100d7e50f4120 to your computer and use it in GitHub Desktop.
Save rodrigograca31/f42c34e100d7e50f4120 to your computer and use it in GitHub Desktop.
Javascript function to decrypt text encrypted by Caeser cipher.
function caeser(number, caeser){
for(i=0; i< caeser.length; i++){
if(caeser.charCodeAt(i)>=65 && caeser.charCodeAt(i)<=90){
if(caeser.charCodeAt(i)+number>90){
document.write(String.fromCharCode((caeser.charCodeAt(i)-90)+64+number));
}else{
document.write(String.fromCharCode(caeser.charCodeAt(i)+number));
}
} else {
document.write(String.fromCharCode(caeser.charCodeAt(i)));
}
}
}
caeser(3, "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD");
//This example comes from Wikipedia: http://en.wikipedia.org/wiki/Caesar_cipher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment