Encode and decode secret messages

Detailed instructions
How to decode

1. Check one of the 4 choices below.

Send me a coded secret message.
Send me the answer to secret message number
Encode my message (typed in the box below).
Decode my message (typed in the box below).
Type the message to encode :


2. Check or fill in the information below.

Type of code: Addition or Multiplication
Letters to numbers: A=0, B=1, ..., Z=25 or A=2, B=3, ..., Z=27
Modulus: (must be an integer at least 26 if A=0, and at least 28 if A=2)
Encoding number: Encoding number: (must be an integer; see below for requirements for multiplication codes)

3. Click the appropriate button.


Detailed instructions (dos and don'ts)

How to decode

The encoding/decoding procedure is based on clock arithmetic. This is how the message is encoded if you're using an addition code with A=0:
  1. Each letter is converted to a number, with A=0, B=1, through Z=25.
    ABCDEFGHIJKLM
    0123456789101112
    NOPQRSTUVWXYZ
    13141516171819202122232425
  2. These numbers (0 through 25) are thought of as numbers on a clock, where the number you have for the "modulus" is the number of hours on the clock. If you use the 26 that is already typed in, you have a 26-hour clock, where 0 is the nhour clock, where 0 is the number after 25.
  3. Each letter of the message (now a number) is encoded by adding the encoding number you chose. Addition is on the clock. For example, if your encoding number is 5 and the modulus is 26, then 0 gets encoded as 5, 17 gets encoded as 22, and 25 gets encoded as 4 (remember that the number after 25 is 0: 25+1 = 0).
So, working backwards through the encoding instructions, here is how to decode.
  1. Each number of the encoded message is decoded by subtracting the encoding number you chose. Remember that subtraction is on the clock. For example, if your encoding number is 5, then 7 gets decoded as 2, 22 gets decoded as 17, and 3 gets decoded as 24 (remember that the number before 0 is 25: 0-1 = 25, so 3-5 = -2 = 24).
  2. Each number is converted back to a letter, with A=0, B=1, through Z=25.
If you used a multiplication code, each number gets multiplied by, instead of added to, the encoding number. The inverse operation to multiplication is division, so to decode the message, the recipient has to divide by the decoding number. But this turns out to be tricky on a clock. It's impossible if your encoding number and the modulus have a prime factor in common. If they don't have any primes in common, you divide by multiplying by the multiplicative inverse. This is the number so that encoding number x its inverse = 1 on the clock. One way to find it is trial and error. There are better ways; check back later for details. details.