Last active
January 15, 2018 08:36
-
-
Save charsi/eb4895999f68a79ccb68dd6428bca415 to your computer and use it in GitHub Desktop.
Testing diffie-hellman https://www.youtube.com/watch?v=Yjrfm_oRO0w
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
// Code describing how Diffie-Hellman key exchange works. Suprisingly simple to understand. | |
// This does not work because Javascript can't deal with large numbers. | |
let g = 5; | |
let n = 37; | |
let pvtA = 5; | |
let pvtB = 8; | |
checkDiffieHellman(pvtA,pvtB,g,n); | |
function checkDiffieHellman (a,b,g,n){ | |
var pubA = Math.pow(g,a)%n; | |
var pubB = Math.pow(g,b)%n; | |
var secretA = Math.pow(pubA,b)%n; | |
var secretB = Math.pow(pubB,a)%n; | |
console.log(secretA,secretB); | |
if (secretA === secretB){ | |
console.log('yep this worked'); | |
} else { | |
console.log('javascript ran into js-infinity',' or 9007199254740991' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment