Java Code:
public class JavaApplication3 
{
    public static void main(String[] args) 
    {
            BigInteger p = new BigInteger(String.valueOf(3571));

            BigInteger q = new BigInteger(String.valueOf(2063)); 

            BigInteger n  = p.multiply(q);

            BigInteger tOfN = new BigInteger(String.valueOf(p.subtract(new BigInteger("1")).multiply(q.subtract(new BigInteger("1")))));
            
            Random randNum = new Random();  
            
            BigInteger publicKey = computePublicKey(randNum, tOfN);

            BigInteger privateKey = publicKey.modInverse(tOfN);
            
            System.out.println("Found Private Key. Val = " + privateKey);
            
                  
    }
    
    
    public static BigInteger computePublicKey(Random randGen, BigInteger totientN)
    {
        boolean isSufficient = false;

        int temp;
        
        BigInteger tempPubKey;
       
        while(isSufficient == false)
        {

         temp = totientN.intValue();
         tempPubKey = new BigInteger(String.valueOf(randGen.nextInt(temp)));
         System.out.println(tempPubKey);
       if((tempPubKey.compareTo(new BigInteger("1")) == 1) && (tempPubKey.compareTo(totientN)) == -1)
         {     
             System.out.println("Found number in range.");
         if(tempPubKey.gcd(totientN).intValue() == 1)
            {
                    System.out.println("Found GCD.");
            
                    System.out.println("Found public Key. Val = " + tempPubKey.intValue());
                    return tempPubKey;
             }
             
         }
        }
        return new BigInteger("0");
        
       
    }
}
As some of you might have guessed, just a little implementation of the RSA algorithm. I can compute the public key fine, and in theory, the private key should be very easy and quick too compute, but it's not. The "modinverse()" function doesn't seem to be crunching out the correct numbers, because when I do (plaintext^publickey) mod n, I get a number that, when decrypted, doesn't equal the plaintext. I'm seriously confused guys, so can you dudes spot anything wrong here?