rodrigograca31
9/16/2014 - 11:53 PM

Javascript function to decrypt text encrypted by Caeser cipher.

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