If two numbers are relatively prime then their greatest common divisor is 1 (that's what "relatively prime" means, after all). So calculate their gcd and see if it's 1 or not. (It should be a trivial task to find an algorithm for the greatest common divisor - Euclid's is simple enough to implement, and the fanciest arithmetic is needs is the modulus operator. In fact, I posted an implementation here less than twenty-four hours ago). Remember that if this is for RSA then you'll need to use the bcmath functions to handle hundred-odd-digit numbers.