4.4. Relating Modular Arithmetic to the Caesar Cipher#
Returning to our task of enciphering the letter x
with a key of
So, how do we find this unique number between
If your computed value is greater than
, repeatedly subtract from the value until it falls between and .If your computed value is less than
, repeatedly add until it falls between and .
Performing this algorithm is equivalent to determining
Revisiting the Caesar Cipher#
We could update the encipher algorithm for the Caesar Cipher as follows:
Convert plaintext letter to a numerical value,
Add the key value,
, to the plaintext value.Determine
.Use this value to determine the ciphertext letter.
Repeat until all plaintext letters have been converted to ciphertext letters.
Notice that Step 3 is valid even if
The deciphering algorithm is now almost identical to the encipher algorithm, with the only difference being how the key is used:
Convert ciphertext letter to a numerical value,
Subtract the key value,
, from the ciphertext value.Determine
.Use this value to determine the plaintext letter.
Repeat until all ciphertext letters have been converted to plaintext letters.
Implementing the Refined Algorithm by Hand#
Let’s practice the new algorithm using the plaintext message zebras eat grass
and key =
plaintext z e b r a s ...
P 25 4 1 17 0 18 ...
P + k 40 19 16 32 15 33 ...
P+k MOD 26 14 19 16 8 15 7 ...
ciphertext O T Q I P H ...
And now, the deciphering algorithm on the ciphertext messsage BARFZ N...
and key =
ciphertext B A R F Z N ...
C 1 0 17 5 25 13 ...
C - k -12 -13 4 -8 12 0 ...
C-k MOD 26 14 13 4 18 12 0 ...
plaintext o n e s m a ...