# Wrap around caesar cipher pset2

With the mod math, (Plainletter+key)%26 could give a remainder, an int. This remainder may not be the int number for the corresponding cipher letter. how to wrap around this remainder if it falls out side of the alaphabet int values?

The remainder of (Plainletter+key)%26 will ALWAYS range from 1 - 25 inclusive, so it will definitely correspond to a letter.

• Hi Ronga, Lets say the alphabets(A thru Z) are in an array, regardless of case sensitive. The remainder could be the indices of this array, correct? Then index would point out to the alphabet? Then convert the letter into corresponding decimal /int number of the ASCII relationship, correct? – aguy01 May 31 '16 at 14:29
• Exactly, A=0 and Z=25, ignoring case. If your fear is that you will get (Plainletter+key)%26 = 26 or 27, mathematically that will never happen. For that matter, you don't even need to define an array containing the letters of the alphabet. The following, for example, will print "Y", which is ASCII value 89: printf("%c", 89) – ronga Jun 2 '16 at 5:52
• Great!! A being the upper bound and Z being the lower bound works fine for the remainder. Remainder will always be within these bounds.The next step is to work with the int values of the corresponding A thru Z to get the cipher letter. Now its math game. Thank you for the discussion! – aguy01 Jun 2 '16 at 13:15

You need to review the class material on this technique. The modulo operation only works when letters are represented by numbers from 0 to 25 inclusive. It won't work on ASCII values of letters. You need to convert ASCII values down to numbers from 0 to 25, do the shift, apply the modulo and then convert back to ASCII.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

• Cliff B, Thank you for the comment! need more help here. Lets say Y has ASCII value 89(decimal number), how this could be converted into a number between 0 and 25? The only possible number would be the Y index in the alphabet, which is 24. is that what was meant by converting numbers from 0 to 25? Then apply the mod rule, and ASCII conversion. does this sound rite? – aguy01 May 31 '16 at 15:42
• Y can be converted to 0 by removing 89, however if you remove the Value of A from Y it will take you to the letter it is in the alphabet. Once you have this you can apply the shift then re-add the value for A...depending if it is a capital or not – Chris Jun 2 '16 at 1:22
• Awesome! Thank you for helping! – aguy01 Jun 2 '16 at 13:16