We have seen how addition be used in encoding. To prevent the result from getting bigger and bigger, we can use cyclic addition. We choose a cycle length, and call this n. Every time a result goes beyond n, we simply divide the result by n, keeping only the remainder. The remainder of division by n is always a number less than n. This, as you'll see, is important for improving our previous encoding schemes.
The technical term for cyclic math is modular arithmetic, and the cycle length n is called the modulo. We write:
x mod nto mean the remainder of number x divided by n.
The best way to represent a cyclic world is a circle, but we can use a linear diagram:
0 1 2 3 4 5 ... n +------+------+------+------+------+------+------+------+------+------+As long as we treat the right-end (n) the same as the left-end (0), this is effectively a circle, or cycle: a world without ends.
An example of cyclic math being used in daily life is the counting of weekdays.
We can modify our encoding by addition as follows:
To apply cyclic addition to our encoding, we need to determine the chop size. Since chopping the data stream by chunks of b-bits means you get numbers ranging from 0 to 2b-1, we can take them as numbers in modulo n=2b. Or, if we have chosen the modulo n, we just take b such that 2b < n. In math terms, b is the integer less than log2n.
Encoding by cyclic addition is sometimes called Casear cipher. Let's see how this cyclic add can do encoding:
You can verify the calculations by this Modulo Addition Calculator.
Back to table of content
If you think of addition as taking steps forward, then subtraction is taking step backwards. Within ordinary math, going backwards is the only way to undo going forward. In the world of cyclic math, however, there is an alternative method:
0 1 2 3 e n +------+------+------+------+------+------+------+------+------+------+ +----------------------------------> e steps d steps +---------------------------------->For a cyclic world of modulo n, the right end (n) is the same as the left end (0). After you have taken e steps forward, you can take a further d steps forward to reach the right end (n), which is the same as returning to the starting point (0). For the two sets of steps to undo each other, it is easy to see that:
e + d = n or d = n - e
This is related to the fact that cyclic math deals with remainders: there are no negative numbers (remember the range?).
Therefore, in cyclic arithmetic, you can cancel addition by another addition. This allows us to view encryption and decryption in a different light.
Back to table of content
In cyclic arithmetic of modulo n, let us do encryption by the key e, that is, (add e, mod n).
Then, we can do decryption by another key d, that is, (add d, mod n).
What we need to have is that (add e, mod n) and (add d, mod n) cancel each other.
We can achieve this by taking d = n-e, for cyclic addition.
We call (e,n) the encryption key.
We call (d,n) the decryption key.
Both encryption and decryption use the same method: addition modulo n.
Note that we can swap the keys: they are just inverses with respect to the underlying method (cyclic addition) which is identical in both encryption and decryption.
Let's see how this coding scheme works. Here you can choose a modulo n. When you click the "Generate" button, a pair of keys will be generated: one is e, the other is d = n-e. The chop-size b-bits is determined by the modulo chosen. Then press the button "Casear Again" and scroll up to view how the message is encoded/decoded by this pair of keys.
Back to table of content
Let's take a look at these two ways to encode using cyclic addition:
Back to table of content
We need to improve this scheme using cyclic addition, because of the following weakness.
If someone knows the encode key (e,n), the decode key (d.n) can be easily deduced. In this case of cyclic addition, d = n-e. As a result, he/she can read any encoded message sent according to this method. Because of this weakness, we must keep both keys secret.
Is there a way to make the deduction of the decode key difficult even if the encode key is exposed? If this is possible, we can just keep one key secret.
We shall investigate this possibility in the next part: cyclic multiply encoding.
Back to table of content