Caesar Cipher (Swift) - Step 13 "Wrap around"

Hi, I’m a little confused about exactly why the remainder operator, %, fixes the out of range problem in step 13 of the Caesar Cipher. Could someone please explain this? Thank You!

Hi,

Could you link to the problem?

From memory, the modulo operator does as you say, returns the remainder. Since the english alphabet has 26 letters, to shift to the right of that means to go to the beginning numbers. So if we shift 2 letters from Z to the right we want to end up at B. It just happens that a possible way to do this is through the operation 28 % 26 = 2.

1 Like

This was really helpful. Thanks so much!