← Back to all posts
Ceasar Cipher using java

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?

heyitsmarcus (287)

I did an algorithm like this a couple years ago with JavaScript. It's going to be fairly similar for Java, but before I hand over the solution, the Caesar cipher I believe is just the `rot13` cipher where characters are shifted upwards by 13 decimal values.

Are your inputs going to be upper and lower case? Or are they just one case?

pkolla (0)

@heyitsmarcus Sounds interesting, I haven't used JavaScript on here yet, but, guess it will be a learning experience? As for the inputs, they will be lower case.

heyitsmarcus (287)

@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!

pkolla (0)

@heyitsmarcus Okay, thank you for the tips!

heyitsmarcus (287)

@pkolla I can't wait to see what you come up with!

heyitsmarcus (287)

@pkolla Were you able to solve this?