P
P
PRIYD2020-10-04 09:38:35
JavaScript
PRIYD, 2020-10-04 09:38:35

Why are different keys obtained in Diffie-Hellman?

Hello.

Problem: I am writing a chat on sockets and when creating a shared secret key using the Diffie-Hellman protocol, this very shared secret is not obtained. Features below.

Question: how to make sure that the shared secret key is correctly generated.

function computePartial(base, module, secret) {
    return Math.pow(base, secret) % module;
}

function computeCommon(module, partial, secret) {
    return Math.pow(partial, secret) % module;
}


module - a simple three-digit number (719)
base - a three-digit number (736)
secret - any two-digit

number

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-10-04
@PRIYD

1. All calculations must be in integers. Your Math.pow yields a real value greater than Number.MAX_SAFE_INTEGER, which makes the calculation pointless.
2. base (or g in the standard notation) must be a primitive root modulo module (or m in the standard notation). This means that the following conditions must be met:
g i % m ≠ 1, 1 ≤ i < m-1
g m-1 % m = 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question