**What is an Affine Cipher?**

According to Wikipedia: "

*The affine cipher is a type of monoalphabetic substitution cipher, wherein each letter of an alphabet is mapped to its numeric equivalent, encrypted using a simple mathematical function, and converted back to a letter. The formula used means that each letter encrypts to one other letter, and back again, meaning the cipher is essentially a standard substitution cipher with a rule governing which letter goes to which. As such, it has the weaknesses of all substitution ciphers. Each letter is enciphered with the function (ax + b) mod 26, where b is the magnitude of the shift.*"

**Encryption:**

In the affine cipher, the letters of an alphabet are mapped to the integers in the range 0 to m-1.

At this point, the each letter of the given text is converted to the ciphertext letter using Modular arithmetic.

E(x) =

*(ax + b)*mod*m**Where a and b are the key of the cipher and*

*m*is the modulus of the size of the alphabet.**Decryption:**

Decryption is derived from the above Encryption function.

D(x) =

Where a and b are the key of the cipher and

1=

*a*mod^{-1}(x-b)*m*Where a and b are the key of the cipher and

*m*is the modulus of the size of the alphabet.*a*: modular multiplicative inverse of^{-1}*a*modulo*m.*It Satisfies the equation1=

*a**a*mod^{-1 }*m*The multiplicative inverse of

*a*only exists if

*a*and

*m*are coprime.

**Example:**I have written a program using an example where the input string is:

"This is the input that will be encrypted and decrypted using Affine Cipher". Currently this program takes a sentence and returns in all uppercase letters after encryption and decryption.

**Code Snippet:**

Input: This is the input that will be encrypted and decrypted using Affine Cipher.

Output: THIS IS THE INPUT THAT WILL BE ENCRYPTED AND DECRYPTED USING AFFINE CIPHER

Have any questions or suggestions ? Lets discuss in the comments.

## 0 Comment to "What is an Affine Cipher ?"

## Post a Comment