# What is the correct idiom for mapping a 0 value in a modulo n expression back to n?

What is the correct idiom for mapping the $0$ value in a modulo $n$ expression back to $n$.

For example if I want to be sure that any integer value maps back to the index for a character in the alphabet, I might use something like

letterIndex[l_]  = First@FirstPosition[ToUpperCase /@ Alphabet[], l];
letterIndex[l_, rot_] := Mod[letterIndex[l] + rot, 26] /. 0 -> 26;


But this look stupid to me and I feel like I'm missing something idiomatic to Mathematica (or to modular equivalences — which have always frustrated me — in general).

• You mean Mod[{1, 2, 3, 4, 5, 6, 7}, 3, 1]? – Kuba Apr 17 '15 at 19:49
• @Kuba: I don't get it? – orome Apr 17 '15 at 20:48
• I mean Mod[x, 26]/.(0->26) can be done with Mod[x, 26, 1]. – Kuba Apr 17 '15 at 21:02
• @Kuba: Duh! I should have looked a bit more closely at the doc! – orome Apr 18 '15 at 12:29

letterIndex2[l_, rot_: 0] := Mod[First@ToCharacterCode[l] - 64 + rot, 26, 1]