Caesar shift
Hi, I'm making a C# program and part of it is based on a Caesar shift. I have searched examples of Caesar shifts online but I do not really understand how they work, for example some use modulus. I want to know how I can make it so if a character like Z is shifted forward by 1 letter it will loop back to A. Thank you! :D
6 Replies
TheRanger#3357
REPL Result: Success
Console Output
Compile: 589.674ms | Execution: 67.987ms | React with ❌ to remove this embed.
thank you, i'm not entirely sure how this code works though, what is the modulus for?
The modulus is for array wrapping.
ie. You have an array of [A-Z] with indices [0-25]. So if you add one to Z, you get index 26 -> 0, which is A.
ohh, why does that work? I thought the modulus was for remainders
is this a second use?
this is the remainer
26 / 25 is 1 with a remainder of 1
if you would shift 'Z' by 105, you would get (25 + 105) % 25 = 5
ohhh i see
thank you