我已经在C++中实现了RSA算法,程序正在运行,但srand调用正在使程序变慢.我使用srand生成两个素数和加密密钥(e).这是片段
...............................................
do
{
p = make_prime_number();
q = make_prime_number();
}while(p == q);
phi = (p - 1) * (q - 1);
n = p * q;
do
{
e = random_builder (20);
int *t = extended_gcd (e, phi);
d = t[0];
}while(gcd(e, phi) != 1 || d < 1 || d >= n );
...............................................
int random_builder(const int max)
{
srand(time(NULL));
return rand() % max + 1;
}
bool is_prime(const int num)
{
for(int i = 2; i <= …Run Code Online (Sandbox Code Playgroud) 请考虑以下部分代码.
#include<iostream>
using namespace std;
class A
{
private:
int *x;
public:
A(int a)
{
cout<<"creating "<<a<<" "<<this<<endl;
x = new int;
*x = a;
}
A(A *a)
{
this->x = a->x;
}
~A()
{
cout<<"destroying "<<x<<endl;
delete x;
}
A *operator+(A a)
{
return new A(*x + *(a.x));
}
void display()
{
cout<<*x<<endl;
}
};
int main()
{
A a(5);
A b(10);
A c = a + b;
cout<<"control returns to main"<<endl;
a.display();
b.display();
c.display();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它产生以下输出. …