I'm having trouble using the hyper-geometric test on a 2x2 contingency table. I have listed the null hypothesis below.

Assuming the null hypothesis is: $$P = \frac{A}{A+B} = \frac{C}{C+D}$$ From here, how do I proceed with the hyper -geometric test? I'm aware of the equation for this test: $$P(X = k) = \frac{{a\choose x}{{N-a}\choose{n-x}}}{N \choose n}$$ where $a$ represents the number of successes.
However, how do I apply this to the contingency table.
Ultimately, I'm trying to write an algorithm that will read in data and do these calculations, hence, if there is an easier/more generalized form of this equation, I'll be interested to know.