This program generates an RSA encrypted message which is further broken down into Shamir Secret shares. It also decrypts the encrypted message back to its original form.
Running this program requires pycryptodome library.
pip install pycryptodome
The basic idea of how RSA encryption/decryption works is the difficulty of factoring a very, very large number in a timely manner.
The formula to encrypt is:
The foundation of this relationship is what is known as the Euler's Totient function. Euler's Totient function states that phi_N is the count of integers mod N relatively prime to N, which is simply (p - 1) * (q - 1). For example, if N = 15 where p = 3 and q = 5, then the integers mod N relatively prime to N would be {1, 2, 4, 7, 8, 11, 13, 14}. The length of this set is 8, which is the same as (3 - 1) * (5 - 1) = 8. Therefore, phi_N = 8.
The idea of Shamir Secret Sharing is to release the message, m, only if a cerntain number of users are present called the quorum. The secret message can be divided up into however many fragments, but as long as the quorum is met, then the secret can be released. The fragments are formed through system of linear equations taking the form: f(x) =
For example, it can be divided among 5 people with
- f(1) =
$a_2 + a_1 + a_0$ (mod N) - f(2) =
$4a_2 + 2a_1 + a_0$ (mod N) - f(3) =
$9a_2 + 3a_1 + a_0$ (mod N) - f(4) =
$16a_2 + 4a_1 + a_0$ (mod N) - f(5) =
$25a_2 + 5a_1 + a_0$ (mod N)
One user holds one quation, and any 3 equations out of the 5 can be used to solve for