Algorithms for RSA key generation, encryption and decryption