Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a code to generate a public key and a private key value. Below is the code :

C#
void keys(long long int &e_key,long long int &d_key,long long int phival)
    {

        e_key = genrndnum(100,(phival-1));

        while(gcd(e_key,phival)!=1)
        {
                e_key = genrndnum(100,(phival-1));

        }

        d_key = genrndnum(100,(phival-1));

        while((d_key*e_key)!=(1%phival))
        {
            Sleep(1000);
                d_key = genrndnum(100,(phival-2));

        if((d_key*e_key)==(1%phival))
        {
            return;
        }
        }


The problem is i don't get the correct encryption and decryption exponents.

What is wrong with above code ?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900