Skip to content

Instantly share code, notes, and snippets.

@dustinmoris
Last active September 13, 2016 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinmoris/93b5210f88927839da034d28baaf30eb to your computer and use it in GitHub Desktop.
Save dustinmoris/93b5210f88927839da034d28baaf30eb to your computer and use it in GitHub Desktop.
Calculate RSA d parameter
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