Skip to content

Instantly share code, notes, and snippets.

@cangevine
Created September 18, 2013 15:17
Show Gist options
  • Save cangevine/6610698 to your computer and use it in GitHub Desktop.
Save cangevine/6610698 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script>
var message= prompt("type your message son");
var key = 2 ;
var alpha= "abcdefghijklmnopqrstuvwxyz" ;
var length= message.length ;
for( i=0 ; i <= length ; i++){
var character = message.charAt(i) ;
var index = alpha.indexOf(character) ;
var newLetternum= index + key ;
var newLetter= alpha.charAt(newLetternum) ;
if( newLetter == "z"){
document.write("b") ;
}else if(newLetter == "y" ){
document.write("a");
}else{
document.write(newLetter);
}
}
// there is a c at the end that is not supposed to be there I dont know why. Sorry BC.
</script>
</head>
<body onload="message">
</body>
</html>
@cangevine
Copy link
Author

---- The spacing and formatting of your page is pretty sloppy and hard to read. Please take a little more care with organization next time.
#18: Your algorithm up to this point looks great. This line is problematic in that it comes before you handle the scenarios in which the cipher text goes beyond the last letter of the alphabet.
#20 & others: Introducing an if statement here is great. The mistake is handling this on a case-by-case basis. What if the plain text is "charles" and the key is 20? Are these conditional statements enough to handle that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment