Chapter 15 – The Affine Cipher 213
THE AFFINE CIPHER
Topics Covered In This Chapter:
The Affine Cipher
Generating random keys
How many different keys can the affine cipher have?
“I should be able to whisper something in your ear,
even if your ear is 1000 miles away, and the
government disagrees with that.”
Philip Zimmermann, creator of Pretty Good Privacy (PGP), the
most widely used email encryption software in the world.
This chapter’s programs implement the multiplicative and affine ciphers. The multiplicative
cipher is like the Caesar cipher from Chapter 6, except it uses multiplication instead of addition.
The affine cipher is the multiplicative cipher, which is then encrypted by the Caesar cipher on top
of that. The affine cipher needs two keys: one for the multiplicative cipher multiplication and the
other for the Caesar cipher addition.
For the affine cipher program, we will use a single integer for the key. We will use some simple
math to split this key into the two keys, which we will call Key A and Key B.