Last active
September 13, 2016 20:40
-
-
Save dustinmoris/93b5210f88927839da034d28baaf30eb to your computer and use it in GitHub Desktop.
Calculate RSA d parameter
This file contains 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
let rec eGCD a b = | |
if a = 0 then b, 0, 1 | |
else | |
let gcd, x, y = eGCD (b % a) a | |
gcd, y - (b / a) * x, x | |
let calcRSAd e n = | |
let gcd, x, _ = eGCD e n | |
if gcd = 1 then x + n | |
else failwith "e and n must be coprime." | |
// Example | |
// 7 * d mod 288 = 1 | |
// let d = calcRSAd 7 288 --> d = 247 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment