The Caesar-shift Cipher is a simple (and by no means secure) cipher that apparently was used by Julius Caesar. It's very simple and can easily be done by hand. The fundamental operation is to "shift" a letter by some fixed shift-value, which is agreed upon beforehand by the participants. See the original SI110 symmetric encryption notes for more general-purpose information.
For our purposes, all symbols - whether in the key, plaintext or
ciphertext - are characters in the ASCII range 42-122
inclusive.
We will represent the shift value by a single character in
that same range: 42 is a shift of zero, 43 is a shift of 1,
and so on.
In the following, we will go back and forth between
treating a character as an integer (via ASCII) and integer as a
character. In code, you must make explicit casts, like
(int)c - 42
or (char)(i + 42)
.
key = k0 k1 ... kn
of characters.sc = 42 +
(
(
18 + (k0 - 42) + (k1 - 42) + ... + (kn - 42)
)
mod 81
)
ki
has ASCII value outside the range 42-122 it is an ERROR!
k = sc - 42 p = pc - 42 c = (p + k) mod 81 cc = 42 + cTo encrypt an entire plaintext message, simply use the above to separately encrypt each character of the plaintext.
k = sc - 42 c = cc - 42 p = (c + (81 - k)) mod 81 pc = 42 + pTo decrypt an entire ciphertext message, simply use the above to separately decrypt each character of the ciphertext.