The Cryptography Management Kit includes basic sample source code for the RSA algorithm. The following samples help to illustrate the depth and quality of this:
Typical Pages:
Mukiply two numbers together. If the lengths of the two numbers are M and N, the
length of the result is (M+N).
int AK_RSA_Mul(unsigned short int ul],
unsigned short int v[],
unsigned short int w[])
{
 short int m,n,i,j,su, sv;
 unsigned int k,t;
 n = u[0] & 32767; su = u[0] >> 15;
 m= v[0] & 32767; sv = v[0] >> 15;
if (m == 0  n == 0)
{
 w[0] = 0;
 return (0);
}
for (i = m+; i <= m+n; i++) wli] = 0;
for (j =m; j > 0; j–)
{
 k= 0;
 for (i =n; i > 0; i–)
{ t= u[i] * v[j] + wla + 5] +k;
 w [i + j] = t & 65535;
 k= t >> 16;
}
w[j] =k;
}
 w[0] = m+n;
 AK_RSA_Normalise (w);
 if (su != sv} w[0] = 32768;
 return(m + n);
}
Test if a specific bit is on or off. This is needed by the modular power routine to
determine whether to square and multiply, or just square.
short int bit)
{
 unsigned int k;
 k = ull + (bit>>4)) & (32768>>(bit & 15));
 if (k ! = 0) return(1);
 return (0);
}
The modular power routine is the basis for RSA encryption and decryption, so all
we have to do now is compute RSA key pairs!
unsigned short int Pow[],
unsigned short int Mod[],
unsigned short int Res[])
{
 short int i,m,n;
 unsigned short int q[512],t[512],w[512];
 Res[0] = 1;
 Res[1] = 1;
 for (4 = 0; i <= Bas[0]; i++) t[i] = Bas[i];
 n = (Pow[0] << 4)  1;
 m = 0;
 while (AK_RSA_Test_Bit(Pow,m) == 0) m++;
 for (i =n; i >= m; i–)
{ if (AK_RSA_Test_Bit (Pow, i) == 1)

 if (Res[0] == 1) AK_RSA Short _Mul(t,Res[1],w); else
AK_RSA_ Mul (Res, t,w);
AK_RSA_Div(w,Mod,q,Res};
 if (Res[0] == 1) AK_RSA Short _Mul(t,Res[1],w); else
 AK_RSA Mul(t,t,w);
 AK_RSA_Div (x, Mod, q, t);
{
}
}
return (0);
}