小编Uts*_*sav的帖子

srand导致我的程序冻结

我已经在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)

c++ encryption rsa srand

1
推荐指数
1
解决办法
638
查看次数

在C++中意外调用析构函数

请考虑以下部分代码.

#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)

它产生以下输出. …

c++ oop destructor

0
推荐指数
1
解决办法
334
查看次数

标签 统计

c++ ×2

destructor ×1

encryption ×1

oop ×1

rsa ×1

srand ×1