Sharing Passwords

Diese Seite auf Deutsch

What the heck! This page needs JavaScript, and it seems that JavaScript is not enabled. Maybe you want to use a different browser? ... Or, maybe, the JavaScript part of this page somehow got lost...

If you have received an encrypted piece of a password for emergencies, then the person who gave it to you has hopefully provided additional pieces to others or stored them in meaningful locations. Once you have three different pieces, you can use this page to reconstruct the password - provided it was encrypted and shared using the procedure described here.

If you have a password that in case of an emergency should be accessible to someone when you are not available, you can use this page to split the password into multiple encrypted pieces. These pieces can be shared, for example, with your friends. Only if three pieces are combined, the secret can be reconstructed.

Only simple math is used in the process, so that you can even do the calculations with pen and paper if necessary. Details and further information can be found in the section on the theory.


Reconstructing a Password from Three Pieces

Back to the Table of Contents

If you have received an encrypted piece of a password from someone for emergencies, then that person hopefully has given additional pieces to other people or stored them in meaningful locations. Once you have three different pieces, you can use this page to reconstruct the password - of course only if it was encrypted and shared using the procedure described on this page.

- Status: Empty - Status: Empty - Status: Empty







If the password data and validation data differ, the restored password may be incorrect. Possible reasons for this include that pieces were combined that do not belong together, or incorrect data in the pieces.


Splitting a Password into Encrypted Pieces

Back to the Table of Contents

If you have a password that in case of an emergency should be accessible to someone when you are not available, then on this page you can split the password into multiple encrypted pieces. These pieces can be shared e.g. with your friends, so that only if three pieces are combined, the secret can be reconstructed.







Example description:
This is Maria's user data from 2023 at her local bank, shared with her relatives for emergencies.

then scroll down.

When you give pieces to others, it's best to also provide a copy of this page. It is designed so you can simply save it as a file and open it again; it works entirely without an internet connection.


The Theory Behind It All

Back to the Table of Contents

If you have a password that someone should be able to access in an emergency even if you are not reachable, there are ways to split the password into several encrypted pieces. You can share these pieces with friends, for example. Only when a certain number of pieces are combined can the original password be reconstructed.

This page is about a procedure and the theory behind it when three pieces are needed for reconstruction. There are also procedures that require only two pieces, and there are procedures where you can freely choose the number of pieces needed. However, these procedures are not the subject of this page. A well-known approach for "any number" is Shamir's Secret Sharing - you can find more information and an implementation here: https://gdiet.github.io/secret-sharing/share-compact.html

A System of Equations with Three Unknowns

First, let's assume that it is not about a password, but about a secret number s. If I have a system of equations with three unknowns, and one of them is s, then I can solve the system of equations for s without knowing p and q if I have three linearly independent equations.

If p and q are random numbers, and the three values each for a, b, and c are known, then the following system of equations can be solved for s:

a1 p+ b1 q+ c1 =s
a2 p+ b2 q+ c2 =s
a3 p+ b3 q+ c3 =s

With some effort or a math program, you get the following solution for s:

s=a1b3c2+a2b1c3+a3b2c1a1b2c3a2b3c1a3b1c2a1b3+a2b1+a3b2a1b2a2b3a3b1s = \frac{a_1b_3c_2 + a_2b_1c_3 + a_3b_2c_1 - a_1b_2c_3 - a_2b_3c_1 - a_3b_1c_2}{a_1b_3 + a_2b_1 + a_3b_2 - a_1b_2 - a_2b_3 - a_3b_1}

Now comes the condition of "three linearly independent equations": For example, if a1 = a2 = a3, then the denominator is zero, and we have a problem when dividing. Only if the denominator is not zero can we calculate s.

The following fifteen a/b value pairs have the property that any combination of three a/b pairs is linearly independent:

1/2 2/1 2/4 1/5 5/2 6/3 3/7 4/7 7/5 3/8 7/8 4/9 6/9 9/1 9/3
I determined these value pairs using a program that checks random combinations for independence:
val tuples = for {i <- 1 to 9; j <- 1 to 9} yield (i, j)
while (true)
  val selection = scala.util.Random.shuffle(tuples).take(15)
  if selection.combinations(3).forall {
    case Seq((a1, b1), (a2, b2), (a3, b3)) =>
      a1*b3 + a2*b1 + a3*b2 - a1*b2 - a2*b3 - a3*b1 != 0
  } then println(selection)
Additional value pairs can be determined, but for now, we are not interested in them.

That looks pretty good so far. We can give up to 15 people each a set of independent a / b / c values, so that it always takes three people to reconstruct s. Or does it?

Additional Knowledge

Does it really take three people to gain information about the secret number s? In reality, this is not always the case. This is because people may be able to use additional knowledge about p, q, and s. For example, if it is known that p, q, and s are bytes, i.e., numbers in the range [0..255], and if a c value is 255, then the corresponding p/q values must be 0 and s = c. Or if it is known that only integers are used in the calculation, and if a person has a, b, and c all even, then this person knows that s is also even. These and similar considerations can be used to gain at least some insights about the secret value s from just one or two equations.

The Number Space mod 257

That's why we use a trick: We perform all calculations modulo 257 (mod 257), which gives us the number range [0..256] — a practical space for working with bytes.

Instead of 257, you could also use any other prime number. With mod 101, for example, we would have the number range [0..100], which can also be very practical depending on the application...

For negative numbers in modulo operations, we use the following rules:

-x mod -y = +x mod +y
-x mod +y = +x mod -y = y - (x mod y)
That way, the modulo is never negative. Example:
-17 mod -7 = +17 mod +7 = 3
-17 mod +7 = +17 mod -7 = 7 - (17 mod 7) = 4

For example, if someone knows the values a = 2, b = 2, c = 2, they still have no additional information about s, because

s = (a*p + b*q + c) mod 257
depending on the values of p and q, can be any number in the range [0..256].

Calculating in the Number Space mod 257

Addition      : a + b in the number space mod 257 = (a + b) mod 257
Subtraction   : a - b in the number space mod 257 = (a - b) mod 257
Multiplication: a * b in the number space mod 257 = (a * b) mod 257
Division      : a / b in the number space mod 257 = ... ?
Division is a bit more involved: It is the inverse of multiplication, so "find the number c such that (b * c) mod 257 = a". You calculate c most easily like this: Check if a is divisible by b without remainder. If it is not divisible without remainder, add 257 to a and check again. Repeat this process until you get a number that is divisible by b without remainder. The result of this division is the desired number c.
For negative numbers:
-a / -b = +a / +b                      | in the number space mod 257
-a / +b = +a / -b = 257 - ( +a / +b )  | in the number space mod 257

Sharing Passwords

Now, let's see how to actually share passwords using the above tools:

For example, if you have the following values

a = 4, b = 7, p = 23, q = 218, s = 65
then calculate
a * p + b * q + c = s     | mod 257
c = s - a * p - b * q     | mod 257
c = (65 - 4 * 23 - 7 * 218) mod 257
c = (-1553) mod 257
c = 257 - (1553 mod 257)
c = 257 - 11
c = 246

{
  "a": 4,
  "b": 7,
  "c": [236,6,124,109,87],
  "v": [125,177,78,85,40]
}

Restoring Passwords

License & More Information

(c) 2023 and later by gdiet
License: MIT License

Document version:
2025-06-17
https://github.com/gdiet/secret-sharing/commit/a280212f

Instead of 'more information', maybe you'd like to see
the source code of these pages on GitHub?