Affine Cipher

The Affine cipher (gets it name from the definition of an affine function which is a combination of a translation and scaling) is another example of a substitution cipher where each letter is replaced by another based on some rule.

Encryption

The affine cipher key consists of a pair of integers (a, b) which is used to are used to form the equation ax+b and subsequently used to generate the mapping of each plaintext character to ciphertext character.

Take (3, 5) as an example. Note a must be a co-prime (have no common factors other than 1) to 26 otherwise different characters may map to the same letter and thus wouldn’t be reversible. In group theory this is because a needs to be cyclic generator of the group Z/26Z

(a) 3*0+5=5 (F)
(d) 3*3+5=5 (O)
(x) 3*23+5=74=5 (mod 22) (W)

abcdefghijklmnopqrstuvwxyz
FILORUXADGJMPSVYBEHKNQTWZC

For each letter in your plaintext you replace it it with its corresponding ciphertext letter.

Example

when the clock strikes twelve attack
TARS KAR LMVLJ HKEDJRH KTRMQR FKKFLJ

Decryption

For each letter in your ciphertext you replace it it with its corresponding plaintext letter (the one above it in the mapping).

abcdefghijklmnopqrstuvwxyz - Key (9, 15)
PYHQZIRAJSBKTCLUDMVENWFOXG

FAZC EAZ HKLHB VEMJBZV EFZKWZ PEEPHB
when the clock strikes twelve attack

New: Try it yourself!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.