After doing a good amount of research, it's become fairly obvious that I ought to be using the extended Euclidean algorithm to calculate d from the data that I already have.
However, this isn't an area of mathematics I'm very familiar with, and the algorithm both takes and outputs multiple integers instead of just one.
So, my question is: Which of the numbers that I already have to I need to input into the algorithm, and of the several numbers it outputs, which is the one I'm looking for?