Affine Cryptosystem

Assume the letters A-Z are labeled by 0, … , 25 and the blank is labeled by 26, i.e. the alphabet with a blank is identified with the ring \mathbb{Z}/27\mathbb{Z}. We define the key of an affine cryptosystem to be (a,b), where a\in \mathbb{Z}/27\mathbb{Z}^\times and b \in \mathbb{Z}/27\mathbb{Z}, which defines an enciphering transformation

    \begin{align*} f_{a,b}: \mathbb{Z}/27\mathbb{Z} &\rightarrow \mathbb{Z}/27\mathbb{Z} \\ x &\mapsto ax+b \end{align*}

Example 1: Encipher the message “WELCOME TO THE NEW AGE” using an affine cryptosystem with the key (5,12).

Step 1: Translate the message to the labeling in \mathbb{Z}/27\mathbb{Z}:

\text{``WELCOME TO THE NEW AGE''}
\Downarrow
``22 \;4 \;11 \;2 \;14 \;12 \;4 \;26 \;19 \;14 \;26 \;19 \;7 \;4 \;26 \;13 \;4 \;22 \;26 \;0 \;6 \;4''

Step 2: Apply the encipher transformation:

f_{5,12}(0)=5\cdot (0)+12=12 \equiv 12 \mod 27
f_{5,12}(2)=5\cdot (2)+12=22 \equiv 22 \mod 27
f_{5,12}(4)=5\cdot (4)+12=32 \equiv 5 \mod 27
f_{5,12}(6)=5\cdot (6)+12=42 \equiv 15 \mod 27
f_{5,12}(7)=5\cdot (7)+12=47 \equiv 20 \mod 27
f_{5,12}(11)=5\cdot (11)+12=67 \equiv 13 \mod 27
f_{5,12}(12)=5\cdot (12)+12=72 \equiv 18 \mod 27
f_{5,12}(13)=5\cdot (13)+12=77 \equiv 23 \mod 27
f_{5,12}(14)=5\cdot (14)+12=82 \equiv 1 \mod 27
f_{5,12}(19)=5\cdot (19)+12=107 \equiv 26 \mod 27
f_{5,12}(22)=5\cdot (22)+12=122 \equiv 14 \mod 27
f_{5,12}(26)=5\cdot (26)+12=142 \equiv 7 \mod 27

``22 \;4 \;11 \;2 \;14 \;12 \;4 \;26 \;19 \;14 \;26 \;19 \;7 \;4 \;26 \;13 \;4 \;22 \;26 \;0 \;6 \;4''
\Downarrow
``14 \;5 \;13 \;22 \;1 \;18 \;5 \;7 \;26 \;1 \;7 \;26 \;20 \;5 \;7 \; 26 \;23 \;5 \;14 \;7 \;12 \;15 \;5''

Step 3: Translate the message back to the alphabet from the labeling:

``14 \;5 \;13 \;22 \;1 \;18 \;5 \;7 \;26 \;1 \;7 \;26 \;20 \;5 \;7 \;26  \;23 \;5 \;14 \;7 \;12 \;15 \;5''
\Downarrow
``\text{OFNWBSFH FH BH UFHXFOHMPF}''

Example 2: Decipher the message “WBSFH BHSFHXBO” if we assume we have an affine cryptosystem enciphered with the key (5,12). The deciphering key is given by: (a^{-1},-ba^{-1})=(5^{-1},-12(5)^{-1})=(11,-132)=(11,3).

Step 1: Translate the encypted message to the labeling in \mathbb{Z}/27\mathbb{Z}:

``\text{WBSFH BHSFHXBO}''
\Downarrow
``22 \; 1 \; 18\; 5\; 7\; 26 \; 1\; 7 \; 18\; 5\; 7\; 23\;1 \; 14 ''

Step 2: Apply the decipher transformation.

f_{11,3}(1)=11\cdot (1)+3=14 \equiv 14 \mod 27
f_{11,3}(5)=11\cdot (5)+3=58 \equiv 4 \mod 27
f_{11,3}(7)=11\cdot (7)+3=80 \equiv 26 \mod 27
f_{11,3}(14)=11\cdot (14)+3=157 \equiv 22 \mod 27
f_{11,3}(18)=11\cdot (18)+3=201 \equiv 12 \mod 27
f_{11,3}(22)=11\cdot (22)+3=245 \equiv 2 \mod 27
f_{11,3}(23)=11\cdot (23)+3=256 \equiv 13 \mod 27
f_{11,3}(26)=11\cdot (26)+3=289 \equiv 19 \mod 27

``22 \; 1 \; 18\; 5\; 7\; 26 \; 1\; 7 \; 18\; 5\; 7\; 23\;1 \; 14 ''
\Downarrow
``2 \; 14 \; 12 \; 4 \; 26 \; 19 \; 14\; 26 \; 12 \; 4 \; 26 \; 13 \; 14 \; 22''

Step 3: Translate the message back to the alphabet from the labeling:

``2 \; 14 \; 12 \; 4 \; 26 \; 19 \; 14\; 26 \; 12 \; 4 \; 26 \; 13 \; 14 \; 22''
\Downarrow
``\text{COME TO ME NOW}''