Hacking Secret Ciphers with Python

(Ann) #1
Chapter 14 – Modular Arithmetic and the Multiplicative Cipher 207

Practice Exercises, Chapter 14, Set D


Practice exercises can be found at http://invpy.com/hackingpractice 14 D.


Multiplicative Cipher + Caesar Cipher = The Affine Cipher


One downside to the multiplicative cipher is that the letter A always maps to the letter A. This is
because A’s number is 0, and 0 multiplied by anything will always be 0. We can fix this by
adding a second key that performs a Caesar cipher encryption after the multiplicative cipher’s
multiplication and modding is done.


This is called the affine cipher. The affine cipher has two keys. “Key A” is the integer that the
letter’s number is multiplied by. After modding this number by 26, “Key B” is the integer that is
added to the number. This sum is also modded by 26, just like in the original Caesar cipher.


This means that the affine cipher has 26 times as many possible keys as the multiplicative cipher.
It also ensures that the letter A does not always encrypt to the letter A.


Figure 14 - 8. The encryption and decryption are mirrors of each other.

The First Affine Key Problem..................................................................................................................................


There are two problems with the multiplicative cipher’s key and affine cipher’s Key A. You
cannot just use any number for Key A. For example, if you chose the key 8, here is the mapping
you would end up with:


A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕
A I Q Y G O W E M U C K S A I Q Y G O W E M U C K S


This mapping doesn’t work at all! Both the letters C and P encrypt to Q. When we encounter a Q
in the ciphertext, how do we know which it decrypts to?! The same problem exists for encrypting
A and N, F and S, and many others.

Free download pdf