Created
May 2, 2017 01:39
-
-
Save AndyNovo/715b2f71827227b64dd9b9a0d9dc77b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function expmod( base, exp, mod ){ | |
if (exp === 0) return 1; | |
if (exp % 2 === 0){ | |
return Math.pow( expmod( base, (exp / 2), mod), 2) % mod; | |
} | |
else { | |
return (base * expmod( base, (exp - 1), mod)) % mod; | |
} | |
} | |
var p = 21755381; | |
var g = 2; | |
var a = Math.floor((p-2)*Math.random()); | |
var b = Math.floor((p-2)*Math.random()); | |
//var a = 20518605; // value I stored from last time | |
var A = expmod(g, a, p); | |
var B = expmod(g, b, p); | |
console.log(a, " Alice private key"); | |
console.log(A, " Alice public key"); | |
console.log(b, " Bob private key"); | |
console.log(B, " Bob public key"); | |
var alice_calculates = expmod(B, a, p); | |
var bob_calculates = expmod(A, b, p); | |
console.log(alice_calculates, bob_calculates); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment