Using a Caesar Cipher with a key higher than 26? When I have experimented with using a key higher than 26 on a Caesar cipher, I have had some very ...interesting... results. The encryption works fine, but when I attempt to decrypt the encrypted message, I am unable to decrypt the message successful. 

I understand that a Caesar can theoretically have a key size of 26, I am just curious as to what would happen with a longer key.
Can somebody assist with both the mathematical side, and if it is possible to use the cipher with a key size higher than 26?

EDIT: In my program I am converting the message to ASCII, adding the key size. To decrypt, I convert it back from ASCII to characters.
The Caesar cipher doesn't just add a value to the character value. What it does is the following (per character in the plaintext):


it converts the character to the index of the character in the alphabet, say 0..25 for uppercase characters;
it performs modular addition of the value, using the size of the alphabet as the modulus;
it converts the resulting index back into a character.


For example you add the key 3 to the 'Z' character, then you:


convert the 'Z' character to the index 25 (index starting with 0, so 26 - 1);
add 3 and perform mod 26: $25 + 3 = 28$, $28 \bmod 26 = 2$;
convert the index 2 to the alphabet, 'C' (as 2 means the third character).


In human language, once you're past 'Z', you start with 'A' again.

Decryption is identical, but it uses subtraction of the key instead of addition.



Great, so what if the key is 26 or higher?

Well, because we use modular addition you can simply do the following: $c = p + k (\mod 26) = p + k - n \times 26 (\mod 26)$. In other words, you can subtract 26 as many times as you want until you get in the index range 0..25 again.

In the example above, using a key of 29 is identical to a key valued $29 - 26 = 3$.

A quick mind also notes that $-3 \bmod 26 = 23$. Which means that decryption with key 3 is identical to encryption with key 23. So basically you only have to create an encryption routine.

You'll also notice that a key that is a multiple of 26 (0, 26, 52 will map the index (and thus the character) back onto itself. So those keys are weak keys and should not be used. A key of 13 will make decryption identical to encryption (as 26 - 13 = 13 again).



Now above explains what you do if you keep to an alphabet size of 26 characters. If you have an alphabet of 26 characters. You can also extend the alphabet, e.g. using the "alphabet":

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,0123456789


In that case you can perform modular addition / subtraction with a modulus of $26 + 26 + 2 + 10 = 64$.



To view a good implementation in Python you can have a look here