Explanation of the affine cipher applet.

Enter text (just type or copy and paste with ctrl-c and ctrl-v) in the top text field, or integers, separated by commas or spaces in the second text field. One of these fields serves as the input for most of the operations.

You can convert text to a list of numbers, or a list of numbers to text (using a goes to 0, b goes to 1 etc.) with the first two radio buttons. The result will be displayed in the output text area.

To apply the affine cipher e(x) = a*x + b to a list of integers, type in the list of integers (separated by commas or spaces), give a value for a and b, select the appropriate radio button (Apply a*x + b) and press the "Do the operation" button.

To apply the affine cipher e(x) = a*x + b to a String, clear the text field for integer input and enter text in the top text field. The remaining steps are the same as applying the cipher to a list of integers.

The list multiples operation will nicely print out the values 1*x, 2*x, 3*x, etc. up to 25*x, all reduced mod 26. This is used to calculate multiplicative inverses mod 26.

To use the Attack operation, enter text in the top text field, type in a value for a inverse (you must calculate this value, and each attack has a^-1 fixed), select the attack radio button and press the operation button.

To see the legal values for a or a^-1, press the Show a values button.

You can clear the output area at any time by pressing the Erase output button.

There is also an operation that calculates x mod 26, for an x value that you enter. Unfortunately, x must be an integer, not something like 21*17.

Here is an example to illustrate that you can actually use this applet to help perform a one-time pad encryption, followed by an example where we perform a known plaintext attack.

Example 1

Let's suppose we'd like to encrypt "Who let the dogs out" with a one-time pad using the key "mission impossibl". Type the plaintext Who let the dogs out into the top text field and convert it to numbers, yielding:
22, 7, 14, 11, 4, 19, 19, 7, 4, 3, 14, 6, 18, 14, 20, 19.
Next, type the key into the top text field and convert that to numbers:
12, 8, 18, 18, 8, 14, 13, 8, 12, 15, 14, 18, 18, 8, 1, 11.
By hand, add the two sets of numbers mod 26:
text
22
7
14
11
4
19
19
7
4
3
14
6
18
14
20
19
key 12 8 18 18 8 14 13 8 12 15 14 18 18 8 1 11
sum 6 15 6 3 12 7 6 15 16 18 2 24 10 22 21 4
Now enter the sums into the integer text field (separate the sums with commas or spaces) and convert them to characters to give:
GPGDMHGPQSCYKWVE

Example 2

Suppose that e(6) = 25 and e(10) = 17. Find the values of a and b. By hand we get that 6a + b = 25 and 10a + b = 17. Subtracting these two equations we get 4a = -8 = 18. The result a = -2 or 24 appears by luck, but there is one more value of a. To solve 4a = 18 mod 26, we look at all multiples of 4, and see which yield 18. Here is the output from the Multiples operation with x = 4:
The multiples, k*4 are:
k =   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
4*k=  4  8  12 16 20 24 2  6  10 14 18 22 0  4  8  12 16 20 24 2  6  10 14 18 22
That indicates that a = 11 or a = 24. Substituting those values back into either of the equations 6a + b = 25 or 10a + b = 17, yield b = 11. Since a = 24 is not a valid value for an affine key, we see that a = 11 and b = 11. Let's check that both solutions would actually generate the given data. Type in 6, 10 to the integer text field, set a = 11 and b = 11 and run the encrypt operation to see that the results are 25 and 17 as stated. Now repeat with a = 24 and b = 11 to see that this also gives 25 and 17.