Question: Rewrite the following function from c to c++ (lines that are not already in c++) int RSA_checkKeys() { /* This function checks whether the keys

Rewrite the following function from c to c++ (lines that are not already in c++)

int RSA_checkKeys()

{

/* This function checks whether the keys exist

* in the file ~/.rsaprivate and ~/.rsapublic

*/

char publicFile[100];

char privateFile[100];

strcpy(publicFile,getenv("HOME"));

strcpy(privateFile,getenv("HOME"));

strcat(publicFile,"/.rsapublic");

strcat(privateFile,"/.rsaprivate");

FILE* fpublic = fopen(publicFile,"r");

FILE* fprivate = fopen(privateFile,"r");

if((!fpublic) || (!fprivate))

{

/* Key files do not exist */

return 0;

}

cout << " Using RSA Key Files : ";

cout << " Public Key File: " + publicFile;

cout << " Private Key File: " + privateFile;

char d_str[1000];

char e_str[100];

char n_str[1000];

/* Get keys */

fscanf(fpublic,"%s ",e_str);

fscanf(fpublic,"%s ",n_str);

fscanf(fprivate,"%s ",d_str);

mpz_set_str(d,d_str,10);

mpz_set_str(e,e_str,10);

mpz_set_str(n,n_str,10);

fclose(fpublic);

fclose(fprivate);

return 1;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!