Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

One wonderfully interesting thing to do with programming is to write code that w

ID: 441005 • Letter: O

Question

One wonderfully interesting thing to do with programming is to write code that will encrypt and decrypt messages. A Caesar Cipher was (reportedly) first used by Julius Caesar in sending military messages to Gaul. It's hard to say whether the cipher was successful at protecting messages... or if all of Caesar's enemies in Gaul just couldn't read Latin. Write a program called Caesar.java that will decode a message that has been "shifted" (or moved over) by three characters. One nice trick is because a char in Java is actually represented as a number, and there are more characters available than just those in the alphabet, we don't have to worry about wrapping around from C back to Z, etc. Also because we don't know loops (yet :-) ), you can assume that the message is a precise length, as seen below. Write code that will decipher this phrase that was, in fact, an actual message of Caesar's in 49 BC (well, as best as we know, at least). And remember - it's in Latin... INPUT: A fixed-length set of 12 characters as a String, such as DOHDLDFWDHVW OUTPUT: "The decoded phrase is: " + result Please keep in if and if else It must be exact!

Explanation / Answer

Here is what you need. I have spent a lot of time in writing this, so please rate :) #include void caesar (char cipher[], int shift); int main () { char cipher[50]; int shift; printf("Enter text to be encrypted IN CAPITAL LETTERS ONLY: "); scanf("%s", cipher); printf("How many shifts do you prefer? 1-10 only: "); scanf("%d", &shift); caesar (cipher, shift); return 0; } void caesar (char cipher[], int shift) { int i = 0; while (cipher[i] != '') { if ((cipher[i] += shift) >= 65 && (cipher[i] += shift)