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).
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.
Derive shift character sc from key = b8T:
----------------------------------
key = b 8 T
k0 k1 k2 ----> 42 + (18 + 98-42 + 56-42 + 84-42) mod 81
98 56 84 \__________________________/ |
130 |
\_________________________________/
42 + 49 = 91 --> [ = sc
Encrypt with shift character sc = [, plaintext character pc = X: --------------------------------------------------------------- k = sc - 42 = [ - 42 = 91 - 42 = 49 p = pc - 42 = X - 42 = 88 - 42 = 46 c = (p + k) mod 81 = (49 + 46) mod 81 = 95 mod 81 = 14 cc = 42 + c = 42 + 14 = 56 = 8 so char '8' is the ciphertext character