For our purposes, all symbols - whether in the key, plaintext or
ciphertext - are characters in the ASCII range 42-122
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 ... knof characters.
sc = 42 + ( ( 18 + (k0 - 42) + (k1 - 42) + ... + (kn - 42) ) mod 81 )
kihas 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.