An affine cipher is a type of simple substitution where each letter is encrypted…
- User
An affine cipher is a type of simple substitution where each letter is encrypted according to the rule c = (a ∗ p + b) mod 26. Here, p, c, a, and b are each numbers in the range 0 to 25, where p represents the plaintext letter, c the ciphertext letter, and a and b are constants. For the plaintext and ciphertext, 0 corresponds to ”a” 1 corresponds to ”b” and so on. Consider the ciphertext QJKES REOGH GXXRE OXEO, which was generated using an affine cipher. Determine the constants a and b. Hint: Plaintext ”t” encrypts to ciphertext ”H” and plaintext ”o” encrypts to ciphertext ”E.” And suppose you know 5^−1 mod 26 = 21 and 11^−1 mod 26 = 19. Encryption
It uses modular arithmetic to transform the integer that each plaintext letter corresponds to into another integer that correspond to a ciphertext letter. The encryption function for a single letter is
E ( x ) = ( a x + b ) mod m modulus m: size of the alphabet a and b: key of the cipher. a must be chosen such that a and m are coprime. Decryption
In deciphering the ciphertext, we must perform the opposite (or inverse) functions on the ciphertext to retrieve the plaintext. Once again, the first step is to convert each of the ciphertext letters into their integer values. The decryption function is
D ( x ) = a^-1 ( x - b ) mod m a^-1 : modular multiplicative inverse of a modulo m. i.e., it satisfies the equation 1 = a a^-1 mod m . To find a multiplicative inverse
We need to find a number x such that: If we find the number x such that the equation is true, then x is the inverse of a, and we call it a^-1. The easiest way to solve this equation is to search each of the numbers 1 to 25, and see which one satisfies the equation.
[g,x,d] = gcd(a,m); % we can ignore g and d, we dont need them x = mod(x,m);
If you now multiply x and a and reduce the result (mod 26), you will get the answer 1. Remember, this is just the definition of an inverse i.e. if a*x = 1 (mod 26), then x is an inverse of a (and a is an inverse of x) - Assistant
Given that the plaintext "t" encrypts to the ciphertext "H" and plaintext "o" encrypts to ciphertext "E," we can set up two equations to find the values of "a" and "b."
Let's convert these letters to numbers. 't' corresponds to 19 ('a' = 0, 'b' = 1, ..., 't' = 19), 'o' corresponds to 14, 'H' corresponds to 7, and 'E' corresponds to 4.
Using the encryption function
E(x) = (ax + b) mod 26, we have:-
For 't' (19) encrypting to 'H' (7):
E(19) = (a * 19 + b) mod 26 = 7 -
For 'o' (14) encrypting to 'E' (4):
E(14) = (a * 14 + b) mod 26 = 4
Now we have a system of equations:
(a * 19 + b) mod 26 = 7 -
- User
decipher the message QJKES REOGH GXXRE OXEO using above information
- Assistant
Now that we have determined the values of "a" and "b" for the affine cipher, with
a = 11andb = 18, we can proceed to decipher the ciphertext "QJKES REOGH GXXRE OXEO" using the decryption function:D(x) = a^(-1) * (x - b) mod 26First, we need to find the modular multiplicative inverse of "a", which is . The hint tells us that .
- User
encrypt the message ITQSA NSWER EVVNS WVSW using above information and see it it matches QJKES REOGH GXXRE OXEO
- Assistant
To encrypt the given plaintext "ITQSA NSWER EVVNS WVSW" using the affine cipher with the constants
a = 11andb = 18that we found earlier, we'll use the encryption function:E(x) = (a * x + b) mod 26We already know the modular multiplicative inverse of is , but for encryption, we use directly. Below, we'll convert each plaintext letter into its numerical equivalent and then apply the encryption function:
- User
see the values of a and b again
- Assistant