PLEASE PLEASE PLEASE: Do not use these examples (specially the real world example) and ... The key generation algorithm is the most complex part of RSA.
doctrina.org