Skip to content

Instantly share code, notes, and snippets.

@cangevine
Created September 18, 2013 14:56
Show Gist options
  • Save cangevine/6610381 to your computer and use it in GitHub Desktop.
Save cangevine/6610381 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript">
var plainTexts = document.getElementById("input");
plainText = plainTexts.value;
var alpha= "abcdefghijklmnopqrstuvwxyz";
var key= 2 ;
// plaintext.charAt (0) then keep going until you reach the length of the phrase//
function ceaserCypher() {
for(i=0; i< plainText.length; i++){
var a = plainText.charAt(i);
var m = alpha.indexof(a) + key;
var b = alpha.charAt(m);
document.write(b);
}
}
</script>
</head>
<body>
<input type= "text" id= "input">
<button onclick = "ceasarCypher()">
</body>
</html>
@cangevine
Copy link
Author

#5: This line is not running properly in Chrome. I believe it is because "input" is a protected word and cannot be an ID. Were you able to text this?
#6: "plainText" appears to be a new variable. Make sure to use "var" to declare it!
#14: What if adding the key puts you beyond the end of the alpha string? This line could be problematic.

---- Things are a little bit hard to read here because of irregular indentation. Make sure to take a second look at that next time.

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