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

I need to write a program which will automatically decrypt any Caesar coded mess

ID: 3640219 • Letter: I

Question

I need to write a program which will automatically decrypt any Caesar coded message. It should rely on the face that the letter e is the most common letter in the English language. So by determining the most common letter in the encrypted message you can figure out how many letters "e" has been shifted to the left and continue to decrypt the entire message. I must also keep uppercase and lowercase the same so I need to have to arrays of characters for both cases. When shifting the letters back (to the left to decrypt) the character need to wrap around at the end.

I need to decompose the program into functions as a design consideration.

My algorithm prototype is:

1. Search the message and count all the letters from a-z and A-Z to find the most common.
2. Calculate how many shifts to the right it is from "e"
3. Apply a left shift in the amount calculated from "e"
4. output to a txt file

I have been stumped on this, I can get bits, like the file i/o or a decrypt prototype but I can't get anything stable. I know you need to use loops to step through character, I just can't get it to work. I have scrapped all that I have in anger and shame!!!

Please Help.

Explanation / Answer

This works perfectly, but the phrase you gave was NOT in line with your definition of the function. You said it should be based off of knowing that the most common letter was 'e'. In the sentence you gave me, the most common letter in the cryptic message was 'u', so my function naturally shifted it back 16 units to make that an 'e', and it is wrong. The e's in your cryptic sentence are actually the q's, not the u's like they should be. Trust me, this program works. Use the Caesar function by passing in a string, and the value you want to shift it back or forward. Negative values for back, positive for forward. Use the find_the_e function by passing in a string, and it will find the most common letter in the string. It will then return the correct number to shift either back or forward. Try it out, I've included some commented code so you can test it. Just uncomment it. #include #include using namespace std; void Caesar(string& phrase, int shift) { if(shift > 0) { for(; shift > 0; --shift) { for(int i = 0; i