• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Changing RSA key

Yony

New Member
Joined
Sep 7, 2007
Messages
318
Reaction score
0
Location
Israel
im trying to change the rsa key for my server..
i've saw somewhere link to rsakeygenerator so i tried to generate a key,
it asks me which key length to generate (i think its 309) and which encryption exponent to use. one more thing, this is the private key..
how do i generate from that the public key?

edit:
the code is encrypted with e,d,m.. but in the source the letters are p,q,d... is it ok?

one more thing, how do i compile Simone's code:

Code:
void makeKeys()
{ 

        #define BITSTRENGTH  1024 
 /* size of modulus (n) in bits */ 
   #define PRIMESIZE    (BITSTRENGTH / 2)  
   /* size of the primes p and q  */
mpz_t d,e,n;
 mpz_t M,c;
 mpz_init(d); 
 mpz_init(e); 
 mpz_init(n);  
 mpz_init(M);  
 mpz_init(c);   
   mpz_t p,q;  
   mpz_init(p); 
     mpz_init(q);  
char* p_str = new char[PRIMESIZE+1];    
char* q_str = new char[PRIMESIZE+1]; 
p_str[0] = '1';    q_str[0] = '1';   
for(int i=1;i<PRIMESIZE;i++)        
p_str[i] = (int)(2.0*rand()/(RAND_MAX+1.0)) + 48;
    for(int i=1;i<PRIMESIZE;i++) 
           q_str[i] = (int)(2.0*rand()/(RAND_MAX+1.0)) + 48;
               p_str[PRIMESIZE] = '\0';
                   q_str[PRIMESIZE] = '\0';
                       mpz_set_str(p,p_str,2);
                           mpz_set_str(q,q_str,2);
                               mpz_nextprime(p,p);
                                   mpz_nextprime(q,q);
                                       mpz_get_str(p_str,10,p);
                                           mpz_get_str(q_str,10,q); 
                                              printf("Random Prime 'p' = %s\n",p_str);
                                                  printf("Random Prime 'q' = %s\n",q_str); 
    /*    *  Step 2 : Calculate n (=pq) ie the 1024 bit modulus    *  and x (=(p-1)(q-1)).    */ 
       char n_str[1000];
           mpz_t x;
               mpz_init(x);
/* Calculate n... */ 
   mpz_mul(n,p,q);
mpz_get_str(n_str,10,n);
    printf("\nn = %s\n",n_str); 
       /* Calculate x... */ 
          mpz_t p_minus_1,q_minus_1;
              mpz_init(p_minus_1); 
                 mpz_init(q_minus_1); 
                    mpz_sub_ui(p_minus_1,p,(unsigned long int)1);
 mpz_sub_ui(q_minus_1,q,(unsigned long int)1);
     mpz_mul(x,p_minus_1,q_minus_1); 
        /*    *  Step 3 : Get small odd integer e such that gcd(e,x) = 1.    */ 
           mpz_t gcd;
               mpz_init(gcd);
                   /*    *  Assuming that 'e' will not exceed the range 
                      *  of a long integer, which is quite a reasonable   
                       *  assumption.    */
   unsigned long int e_int = 65537; 
      while(true)
          {    
                  mpz_gcd_ui(gcd,x,e_int); 
                   if(mpz_cmp_ui(gcd,(unsigned long int)1)==0) 
                              break; 
                                     /* try the next odd integer... */  
                                           e_int += 2; 
          }   
                                               mpz_set_ui(e,e_int);
                                                   /*    *  Step 4 : Calculate unique d such that ed = 1(mod x)    */  
                                                     char d_str[1000];
                                                         if(mpz_invert(d,e,x)==0) 
                                                            {    
                                                                     printf("\nOOPS : Could not find multiplicative inverse!\n"); 
                                     } 
                                        mpz_get_str(d_str,10,d);
                                      printf("\n\n"); 
                                         /*    *  Print the public and private key pairs...    */  
                                           printf("\nPublic Keys (e,n): \n\n"); 
                                              printf("\nValue of 'e' : %ld",e_int); 
                                                 printf("\nValue of 'n' : %s ",n_str); 
                                                    printf("\n\n");  
                                                      printf("\nPrivate Key : \n\n"); 
                                                         printf("\nValue of 'd' : %s",d_str);


}
 
Last edited:
Back
Top