我剛開始拿起C,我正在使用我的代碼中的RSA密碼。但是,這行代碼混淆了我。積分轉發給作者本網站here。C++中這段代碼的含義
char* intmsg = new char[strlen(msg)*3 + 1];
這是可以找到該行的方法。
inline void encrypt(char* msg,FILE* fout)
{
/* This function actually does the encrypting of each message */
unsigned int i;
int tmp;
char tmps[4];
char* intmsg = new char[strlen(msg)*3 + 1];
/* Here, (mpz_t) M is the messsage in gmp integer
* and (mpz_t) c is the cipher in gmp integer */
char ciphertext[1000];
strcpy(intmsg,"");
for(i=0;i<strlen(msg);i++)
{
tmp = (int)msg[i];
/* print it in a 3 character wide format */
sprintf(tmps,"%03d",tmp);
strcat(intmsg,tmps);
}
mpz_set_str(M,intmsg,10);
/* free memory claimed by intmsg */
delete [] intmsg;
/* c = M^e(mod n) */
mpz_powm(c,M,e,n);
/* get the string representation of the cipher */
mpz_get_str(ciphertext,10,c);
/* write the ciphertext to the output file */
fprintf(fout,"%s\n",ciphertext);
}
您發佈的第一位是C++,而不是C. – StoryTeller
新是C++中的keywod,但您只標記了C – Omkant