Why do we keep using the %26 in pset2 when working with Caesar and Vignere? I'm having trouble understanding why it would be helpful to know what the remainder is after dividing by 26?


% 26 will always give you a number between 0 and 25. The Caesar algorithm works on the assumption that your letters A-Z (or a-z) are represented by the numbers 0-25, so if you have 'z' (25) and a key of 7, 25 + 7 is 32. 32 is not within the range, but 32 % 26 is 6, which represents 'g'. Remember that the letters wrap around from 'z' back to 'a' much like a clock wraps around from 11am, 12pm, 1pm, 2pm (ie, 11am + 3 hours is (11 + 3) % 12 (2 pm) because 14 % 12 == 2

  • omg this was not clear from the lecture or explanations, thanks! it makes sense now! and i was trying to manually make a way for the wrap around which seemed overly complicated while this is such a simple solution! thanks for the explanation – xunux Jan 10 '20 at 19:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .