Created
September 18, 2013 14:56
-
-
Save cangevine/6610381 to your computer and use it in GitHub Desktop.
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
| <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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#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.