#14 Affine Cipher

1.4K 4 0
                                        

#Cryptography

LECTURE #14: AFFINE CIPHER

The Affine cipher is an example of a monoalphabetic substitution cipher, wherein, each letter in the alphabet were mapped to its numeric equivalent, encrypted using a simple mathematical function and converted back to a letter which means that the Affine cipher is essentially a standard substitution cipher with a rule governing which letter goes to which.

[ENCRYPTION]
The first step of the encryption is to transform each letters of the plaintext alphabet to the corresponding integer in the range 0 to m−1 and so on. With this done, the encryption process for each letter is given by this formula:
𝐄(𝒙)=(𝒂𝒙+𝒃) mod 𝒎

where:
𝒙= is the integer value of letters in the alphabet
𝒂,𝒃= the key for the cipher (***Key 𝙗 is basically the magnitude of the shift)
mod 𝒎 (modulus 𝒎)= is the length of the alphabet

This means that we must multiply our integer value for the plaintext letter by 𝒂, and then add 𝒃 to the result. Finally, take the mod 𝒎 (it is the length of the alphabet minus 1 [our range 0 to m−1])

Example:
Let's encrypt the word "SWORDCANE".
Keys: 𝒂=7, 𝒃=4

1. Find the integer value of each letters in the plaintext alphabet (A=0, B=1, C=2 and so on.)
2. With the integer value of the plaintext letters, perform the calculations of the values.
¬ 𝐄(𝒙)=(𝒂𝒙+𝒃) mod 𝒎
3. Ensure all the answers were calculated by the modulus and convert the integers back to ciphertext letters.
¬ 𝐄(𝒙)=(7𝒙+4) mod 26

Plaintext: S|W|O|R|D|C|A|N|E
𝒙: 18|22|14|17|3|2|0|13|4
7𝒙+4: 130|158|102|123|25|18|4|95|32
7𝒙+4 mod 26: 0|2|24|19|25|18|4|17|6
Ciphertext: A|C|Y|T|Z|S|E|R|G

Therefore, the encryption of the word "SWORDCANE" to Affine cipher is "ACYTZSERG"

[DECRYPTION]
In deciphering Affine cipher, we must perform the inverse functions on the cipher text to retrieve the plaintext. Once again, we must convert each cipher text letters to integer values. The decrytion process is given by this formula:
𝑫(𝒙)=𝒄(𝒙-𝒃) mod 𝒎

where:
𝒙= is the integer value of letters in the alphabet
𝒄= modular multiplicative inverse of 𝒂
𝒂,𝒃= the key for the cipher (***Key 𝙗 is basically the magnitude of the shift)

***Note: to find the multiplicative inverse of 𝒂, think of a number that when you will multiply to 𝒂 mod 26, you can get an answer of 1.

Example:
Let's decrypt the enciphered text from the word Swordcane: ACYTZSERG
Let's have the same keys: 𝒂=7, 𝒃=4

1. Using the keys: 𝒂=7, 𝒃=4, the first step is to find the modular multiplicative inverse of 𝒂.
¬ 𝑫(𝒙)= 𝒄 mod 𝒎(𝒙−𝒃) mod 𝒎
¬ 𝑫(𝒙)= (𝒂) (𝒛) mod 26
¬ 𝑫(𝒙)= (7) (𝒛) mod 26=1
¬ 𝑫(𝒙)= (7) (15) mod 26=1
¬ 𝑫(𝒙)= 105 mod 26=1
¬ Answer: 15

2. Perform the inverse calculations on the integer value of the ciphertext letters.
¬ 𝑫(𝒙)= 15mod 26(𝒙−4) mod 𝒎

3. Ensure all the answers were calculated by the modulus and convert the integers back to plaintext letters.
¬ 𝑫(𝒙)= 15mod 26(𝒙−4) mod 26

Ciphertext: A|C|Y|T|Z|S|E|R|G
𝒚: 0|2|24|19|25|18|4|17|6
15(𝒚-4): -60|-30|300|225|315|210|0|195|30
15(𝒚-4) mod 26: 18|22|14|17|3|2|0|13|4
Ciphertext: S|W|O|R|D|C|A|N|E

Therefore, the ciphertext "ACYTZSERG" will be decrypted as "SWORDCANE" in Affine cipher.

[GAME]
Now, let's test if you got this lecture. Try to decrypt this one.
Key: a=9, b=2
IWZCZRNAZUYPCPDYKXM

PM Swordcane for your answer.

- LMJC 🎩 -

- LMJC 🎩 -

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.
Codes And CiphersWhere stories live. Discover now