You can reverse the encryption with `Solve`, which can handle modular equations. With[{alphabet = Alphabet[]}, With[{n = Length[alphabet]}, EncryptChar[char_, a_, b_] := Module[{position, shift, mod}, position = Position[alphabet, char][[1, 1]]; shift = Mod[a position + b, n]; alphabet[[shift]]]; DecryptChar[char_, a_, b_] := Module[{position, shift, mod}, position = Position[alphabet, char][[1, 1]]; shift = Solve[a x + b == position, x, Modulus -> n][[1, 1, 2]]; alphabet[[shift]]]]] DecryptChar[EncryptChar["u", 3, 5], 3, 5] >`"u"` Note: I also cleaned up you code a bit.