RSA from first principles

Before first principle implementation deters you from
using encryption, it must be said that .NET has it’s own built in
cryptographic framework. You should not use first principle RSA unless you
are communicating with applications that are not based on .NET or Windows.

RSA is named after its inventors, Rivest, Shamir, and
Adleman. When it was first released it caused such a stir in government
circles it was classified as a military product. This could be understandable,
because it could mean that hostile groups could communicate freely without
the possibility of interception by government intelligence.It was also protected by a US patent,
which prevented derivative versions of RSA emerging.

In September 2000, the RSA patent expired, and
cryptography laws were relaxed dramatically when it was found that policing
the export of this information was unfeasible, especially with the advent of
the Internet. Restrictions still apply today on the export of RSA from the
USA to countries that the U.S. has under sanction (Iran, Cuba, Iraq, Libya,
Syria, Sudan, North Korea).

The RSA algorithm itself is not hugely complex, but the
mathematical formulas involved are quite intricate.The following example will take you step by step through the
RSA algorithm.

Initially, two large random large distinct prime numbers
are chosen, for notation purposes, these are referred to as p and q.

A third number is chosen that is relatively prime to (p-1)*(q-1),
this number is referred to as e, the encryption exponent.

We define a fourth variable, n, such that n = p*q.

Using Euclid's greatest common divisor algorithm. The
decryption component can be determined such that: