Letters are turned into numbers A=0, B=1, …, Z=25 and converted with n=26 as follows.
Encrypt: Enc(m) = (a·m + b) mod 26 Decrypt: Dec(c) = a⁻¹·(c − b) mod 26
a⁻¹ is the inverse of a (the number for which a·a⁻¹ leaves remainder 1 when divided by 26). Characters other than letters are kept as they are, and upper and lower case are preserved.
Why a must be coprime to 26
Only when gcd(a, 26) = 1 does a⁻¹ exist, so the text can be decrypted.
With a=2, for example, A (0) and N (13) both map to the same letter because 2·0 = 0 and 2·13 = 26 ≡ 0, so the original letter cannot be recovered from the ciphertext.
The 12 values of a coprime to 26 are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25.
Finding the inverse (a=5)
The extended Euclidean algorithm finds t such that 26·s + 5·t = 1.
a=1 is a shift cipher (b=3 is the Caesar cipher, b=13 is ROT13)
b=0 is a multiplicative cipher (multiplication only)
a=25, b=25 is Atbash (A↔Z, B↔Y and so on; since 25 ≡ −1, Enc(m) = 25 − m)
How the brute-force attack works
Decrypt the ciphertext with all 312 keys (12 choices of a × 26 of b)
Score how English each result looks: the sum of log-likelihoods of adjacent letter pairs (a table built from about 160,000 letters of Pride and Prejudice), plus 4 × the number of common English words (2+ letters)
Rank by score. If the gap between the first and second candidates is under 3, the tool says they are hard to tell apart
Short texts are easier to get wrong. The README lists how often the first candidate was correct on an evaluation text (A Tale of Two Cities). If the plaintext is not English, this scoring cannot be trusted.