In: Computer Science
Use the Affine cipher algorithm with k1=7,k2=11 to encrypt the following message : I want to get a hundred in this test
In the Affine Cipher Algorithm, every alphabet is first given a numeric serial code as follows:
Alphabet | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Code(x) | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
The code "x" is then changed using the formula f(x) = (k1*x + k2) mod m, where 'm' is the length of the alphabet used and k1, k2 are the keys of encryption.
The encrypted code is then assigned its corresponding alphabet and the encrypted message is generated.
Now, we shall see how the encrypted message is generated for the given message.
Given: Message: I want to get a hundred in this test, k1 = 7, k2 = 11, m = 26
Assigning code to it:
Alphabet | I | W | A | N | T | T | O | G | E | T | A | H | U | N | D | R | E | D | I | N | T | H | I | S | T | E | S | T | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Code(x) | 8 | 22 | 0 | 13 | 19 | 19 | 14 | 6 | 4 | 19 | 0 | 7 | 20 | 13 | 3 | 17 | 4 | 3 | 8 | 13 | 19 | 7 | 8 | 18 | 19 | 4 | 18 | 19 |
Changing the code "x" to f(x) = (7 * x + 11) mod 26
Alphabet | I | W | A | N | T | T | O | G | E | T | A | H | U | N | D | R | E | D | I | N | T | H | I | S | T | E | S | T | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Code(x) | 15 | 9 | 11 | 24 | 14 | 14 | 5 | 1 | 13 | 14 | 11 | 8 | 21 | 24 | 6 | 0 | 13 | 6 | 15 | 24 | 14 | 8 | 15 | 7 | 14 | 13 | 7 | 14 |
Finally, getting the encrypted message by assigning the relevant alphabet to code:
Code(x) | 15 | 9 | 11 | 24 | 14 | 14 | 5 | 1 | 13 | 14 | 11 | 8 | 21 | 24 | 6 | 0 | 13 | 6 | 15 | 24 | 14 | 8 | 15 | 7 | 14 | 13 | 7 | 14 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Alphabet | P | J | L | Y | O | O | F | B | N | O | L | I | V | Y | G | A | N | G | P | Y | O | I | P | H | O | N | H | O |
Final encrypted message: p jlyo of bno l ivygang py oiph onho