Encrypt and decrypt text using this mathematical substitution cipher
The Affine cipher uses a mathematical formula where each letter is first converted to a number (A=0, B=1, ..., Z=25), then transformed using the formula, and finally converted back to a letter.
The Affine cipher is a type of monoalphabetic substitution cipher where each letter in the alphabet is mapped to its numeric equivalent, encrypted using a mathematical function, and then converted back to a letter.
The Affine cipher is a type of monoalphabetic substitution cipher where each letter in the plaintext is mapped to its numeric equivalent, transformed using a simple mathematical function, and then converted back to a letter.
The Affine cipher uses a mathematical formula of the form:
E(x) = (ax + b) mod m D(y) = a^(-1) × (y - b) mod m
Where:
For example, with a=5 and b=8, the letter 'C' (value 2) would be encrypted as:
The value of 'a' must be chosen such that it is coprime with the modulus (26 for the English alphabet), which means they share no common factors other than 1. For m=26, valid values of 'a' are: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25.