Ceasar Cipher using java
pkolla (0)

I'm confused on how to do this code? I've been trying for days now and I've still got nothing. Any examples out there so I can see how it works?

You are viewing a single comment. View All
heyitsmarcus (285)

@pkolla I am going to be off to bed, and I hope no one just gives you the solution because it's much more satisfying (and a better learning experience to figure out).

But, before I head off to Lala Land, I'll leave you with some handy tips:

  1. Check out this ASCII tables website: http://www.asciitable.com/ It will show you the values for each character in the ASCII table which you can use to do the math you'll need to do for this.
  2. Don't overcomplicate the problem. Since you're only targeting lowercase characters, focus on the ASCII table from lowercase a to lowercase z. If you're encoding the cipher: Realize that once you get past z, you'll have to go back down 26 characters into the lowercase range to start over again. If you're decoding the cipher: Once you get below the letter a, you'll have to go back up 26 characters. This is important!
  3. Iterate over each character given to you, analyzing each one individually to see what the modified value (the character minus 13 for decoding or the character plus 13 for encoding) gives you. This goes back to the checking for anything past lowercase z and going back down. But only focus on alphabet characters, so skip any whitespace!

Get some code together, stick it into a Java repl, and see what you can come up with! Good luck!