Skip to content

Instantly share code, notes, and snippets.

@saltimbanc
saltimbanc / dh.js
Created March 27, 2023 05:47
JavaScript implementation of the Diffie-Hellman algorithm for multiple parties. I've based this on: https://crypto.stackexchange.com/questions/1025/can-one-generalize-the-diffie-hellman-key-exchange-to-three-or-more-parties
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function modExp(a, b, m) {
let result = 1;
while (b > 0) {
if (b & 1) {
result = (result * a) % m;
}