What is the relationship between the multiplication method of Russian peasants and modern cryptography? Unlike the commonly studied multiplication procedures, it can be easily adapted to the calculation of degrees, and not products; and in some cryptosystems, the calculation of degrees is required.
I must immediately admit that the article will not be devoted to how Russian peasants managed to exchange information secretly from their landlords.
Multiplication by the method of Russian peasants
If you didn’t know about it before, then this is a rather curious approach to multiplication, which does not require memorizing multiplication tables - for it is enough to have the ability to double and halve whole numbers. It is not very clear how he treats Russian peasants: it seems, the same as the “Danish pastry” to Denmark. This method was known to the ancient Egyptians , who obviously lived much earlier than Russian peasants. ')
The general description of the method is simple, but not too informative. However, let's start with it. If we need to multiply two integers and then we will draw two columns, in the title of one we will write and in the other - . Then we will begin to constantly add new rows, obtained by dividing in half (residue discarded) and doubling and stop when in the column will remain . Finally, we add up all the elements of the column. where value is odd.
Everything becomes much clearer if you give an example. So let's do the multiplication . This gives us a table.
\ begin {array} {| c | c |} \ hline m & n \\ \ hline 13 & 7 \\ 6 & 14 \\ 3 & 28 \\ 1 & 56 \\ \ hline \ end {array}
Now we add the right values, whose left values are odd, which gives us
What, as can be easily seen, is the result .
Of course, it’s interesting why this mysterious procedure works?
If you look in the left column, and walk up to the top, recording when we see an odd number and when we meet the even, we get , That is in binary form (and, of course, this is no coincidence). In fact, this is the standard algorithm for converting numbers to binary form.
Then, as we can see, the duplicate column doubling calculates the product with the appropriate degree therefore their addition with the corresponding odd value in the column is an addition multiplied by these degrees that adds up to .
That is, by this method we can multiply any integers, and moreover - the algorithm is quite effective. It must be admitted that it is not as effective as the methods currently studied with columns or tables, but at least it does not need to memorize multiplication tables.
This is all pretty cute, but it is noteworthy that the method can be slightly transformed to perform much more complicated calculations, which are very useful in modern cryptography (with a public key).
Exponentiation by the method of Russian peasants
We will make two small changes to the algorithm; both will only deal with speakers .
Instead of doubling, we will square
Instead of adding at the end we will multiply.
For each row in the table instead of multiplying to the appropriate degree we will raise it to the appropriate degree . Multiplying all of this will give us .
Let's see how it will work with the same values. and .
\ begin {array} {| c | c |} \ hline m & n \\ \ hline 13 & 7 \\ 6 & 49 \\ 3 & 2401 \\ 1 & 5764801 \\ \ hline \ end {array}
Multiplying the corresponding members gives
What is really equal .
But unlike multiplication, this method is not just sufficiently effective: it is very effective.
If we want to find in degree , then we can do it by multiplying number times . This is how to calculate by addition number times : you can do this, but if more then the time spent can be disposed of with greater benefit.
But thanks to this algorithm, the number of squares needed is a maximum of about more digits (because the binary representation of the decimal number has approximately times more bits than the decimal number of digits), followed by the same number of multiplications.
Of course, for this we need to be able to multiply, but this suits us: the multiplication algorithm allows us to multiply by doubling and adding, and the adapted version allows us to raise the power by squaring and multiplying. Is it a good deal.
Brief introduction to RSA
The point of this is that the method of implementing RSA public key cryptography (Rivest-Shamir-Adleman) (and some others) implies that in order to encrypt and decrypt messages, we need to calculate degrees.
The procedure works as follows: we choose a closed pair of prime numbers and and tell the world the meaning . (Values and we keep secret: the algorithm is based on the fact that the decomposition problem The factors are complex.)
Then we pick the number and find such that on more than a work . We inform the world . (Number we keep a secret. The algorithm is based on the fact that finding without knowledge and is a challenge.)
Now we present the message as an integer. . Encrypted Message Form is the remainder of the division on .
Thanks to the magic of number theory (in fact, this is not magic, but Fermat’s small theorem ), the original message will be the remainder of the division on .
In principle, this is enough, there are already many other descriptions on the Internet, often illustrated with meanings small enough to keep track of all arithmetic calculations.
And here there is one problem.
In practice, the values and at least or , or very large. If we have to re-multiply, the universe will die before we finish. This algorithm reduces the amount of work to quite acceptable proportions. Multiplications (or ) reduced to the number of multiplications, which is a small divisor of the number of digits (or ).
But this is not the only problem.
Value almost incredibly large. We will not be able to write it, even if we used to store one digit each elementary particle in the known universe. How does this work?
The answer is again the theory of numbers. One of the very convenient properties of calculating residuals is that it does not matter at what stage of the calculations we find them. If we need to know the remainder of some value when divided by then you can calculate the whole number and divide it by or, which is much more logical, you can break everything up into stages and take the remainder when the processed value exceeds . In the end, we are guaranteed to get the same result.
RSA Russian Peasants
So now we see how to calculate the encrypted message. You can use the adapted multiplication according to the method of Russian peasants, but now we can add the final touch - when the square of the number exceeds ), we will take the remainder of the division by .
Let's take a look at how this works, on the example of finding the remainder of the division on .
\ begin {array} {| c | c |} \ hline m & n \\ \ hline 13 & 7 \\ 6 & 49 \\ 3 & 2401 \ rightarrow 41 \\ 1 & 1681 \ rightarrow 29 \\ \ hline \ end {array}
What gives us
And this is actually (fuh!) Is the remainder of the division on .
But here is an unexpected outcome. This is an exponent algorithm, commonly referred to as exponentiation (repetitive) squaring. In fact, this algorithm (or its small variation) is used in the implementation of public-key cryptography (for example, in RSA), in which the calculation of degrees is used.
That is what we have come to. The multiplication algorithm, which was used by people who did not know the multiplication table, turned into an exponentiation algorithm that underlies modern cryptographic methods.
Thanks
At MathsJam Gathering 2017, Helen Smith and Linda Goldenberg made a presentation on multiplication techniques, including the method of Russian peasants. It was then that I finally realized that the re-squaring algorithm is an adaptation of the multiplication of the Russian peasants, and I realized that it is worth sharing this awareness with readers. Twenty minutes later, Oliver Masters talked about the Fibonacci matrix and mentioned the re-squaring algorithm for raising to the power of the matrix. Fortunately, he did not connect it with the multiplication algorithm. Five minutes later, Colin Wright (@ColinTheMathmo) summarized the reports and mentioned this connection. But by that time I had already decided to write this article anyway, which I did.