Last active
August 29, 2015 14:06
-
-
Save rodrigograca31/f42c34e100d7e50f4120 to your computer and use it in GitHub Desktop.
Javascript function to decrypt text encrypted by Caeser cipher.
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 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