Implement RSA Encryption
<p>I just had this project to implement RSA Encryption to encrypt and decrypt a message. But somehow when I input a plaintext to encrypt my program just shut off won't run. Any expert can help me out? When I debug there is no any run-time error but till I try to input a message to encrypt my program is died.</p>

<pre><code>    #include&lt;iostream&gt;
    #include&lt;cmath&gt;
    using namespace std;
    #define MAXLENGTH 500  

    int size = 0;
    int p, q;   //the two prime numbers
    int n, phi; //n = p * q，phi = (p-1) * (q-1) 
    int e;      //{e, n}the public key
    int d;      //{d, n}the private key
    int i, j ;
    int clear[MAXLENGTH], Ciphertext[MAXLENGTH];//used to store add // dense 
     before the bright // text and encrypted ciphertext
    int DecryptionText[MAXLENGTH];//Store the decrypted plaintext


    void Encryption()
    {
//encrypt method
cout &lt;&lt; " enter two prime number p and q：" ;
cin &gt;&gt; p &gt;&gt; q ;
cout &lt;&lt; " p = " &lt;&lt; p &lt;&lt; ", q = " &lt;&lt; q &lt;&lt; endl;
n = p * q;//compute  n，
phi = (p - 1) * ( q - 1 );//compute the totient of the product
cout &lt;&lt; " n = " &lt;&lt; n &lt;&lt; ", phi = " &lt;&lt; phi &lt;&lt; endl;
cout &lt;&lt; " choose number between[0，" &lt;&lt; phi - 1 &lt;&lt; "] " &lt;&lt; phi &lt;&lt; " coprime to    3120：";
cin &gt;&gt; e;
float d0;
for( int i = 1; ; i++)
{///compute modular multiplicative inverse of  e * d ≡ 1 (mod phi) 
    d0 = (float)(phi*i+1) / e;
    if( d0 - (int)d0 == 0 )
        break;
}
d = (int)d0;
cout &lt;&lt; endl;
cout &lt;&lt; " e = " &lt;&lt; e &lt;&lt; ", d = " &lt;&lt; d &lt;&lt; endl;
cout &lt;&lt; " The public key is {e,n} = {" &lt;&lt; e &lt;&lt; "," &lt;&lt; n &lt;&lt; "}" &lt;&lt; endl;
cout &lt;&lt; " The private key is {d,n} = {" &lt;&lt; d &lt;&lt; "," &lt;&lt; n &lt;&lt; "}" &lt;&lt; endl;
cout &lt;&lt; endl;

cout &lt;&lt; " enter a prime number to encrypt less than " &lt;&lt; n &lt;&lt; " positive integer（ -1 to end）：" &lt;&lt; endl;
cout &lt;&lt; " The plaintext before encryption：";
for( i = 0; i &lt; MAXLENGTH; i++)
    Ciphertext[i] = 1;
int count;
for(int j = 0; j&lt;MAXLENGTH; j++)
{
    cin &gt;&gt; clear[j];
    if( clear[j] == -1 )
        break;
    count = e;
    while(count &gt; 0)
    {
        //to encrypt Ciphertext =（clear）^ e mod n
        Ciphertext[j] = (Ciphertext[j] * clear[j]) % n;

        count-- ;
    }
}
cout &lt;&lt; " the Ciphertext is：" ;
size = j;//the length of ciphertext
for(int k=0; k&lt;j; k ++)
    cout &lt;&lt; Ciphertext[k] &lt;&lt; " ";
cout &lt;&lt; endl ;
   }

//decrypt method
for(int i = 0; i &lt; MAXLENGTH; i++)
    DecryptionText[i] = 1;
int count;
for(int j = 0; j &lt; size; j++)
{
    count = d;
    while(count &gt; 0)
    {//compute DecryptionText =（Ciphertext）^ d (mod n)
        DecryptionText[j] = ((DecryptionText[j] * Ciphertext[j]) %n);
        count-- ;
    }
}

cout &lt;&lt; " ：";
int k;
for( int k = 0; k &lt; size; k ++)
    cout &lt;&lt; DecryptionText[k] &lt;&lt; " ";
cout &lt;&lt; endl ;
    cout &lt;&lt; " The plaintext before encryption：";
for( k = 0; k &lt; size; k++)
    cout &lt;&lt; clear[k] &lt;&lt; " ";
cout &lt;&lt; endl;
    }
    void main()
    {
Encryption();
char c;
cout &lt;&lt; endl;
cout &lt;&lt; "want decrypt （Y or N）: ";
cin &gt;&gt; c;
if(c == 'y' || c == 'Y')
    Decryption();
else
    return ;
    }
</code></pre>
