⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flintpp.cpp

📁 rsa算法的c++实现,该程序实现rsa密钥对的生成.此密钥用来加密和解密
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  err = sqr_l (n_l, n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_OFL:
        status = E_LINT_OFL;
        break;
      default:
        panic (E_LINT_ERR, "sqr", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::divr (const LINT& d, LINT& r)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "divr", 0, __LINE__);
  if (d.status == E_LINT_INV) panic (E_LINT_INV, "divr", 1, __LINE__);

  err = div_l (n_l, d.n_l, n_l, r.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        r.status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "divr", 1, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "divr", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::mod (const LINT& d)
{
  LINT junk;
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "mod", 0, __LINE__);
  if (d.status == E_LINT_INV) panic (E_LINT_INV, "mod", 1, __LINE__);

  err = div_l (n_l, d.n_l, junk.n_l, n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "mod", 1, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "mod", err, __LINE__);
    }

  return *this;
}


/*const LINT& LINT::mod2 (const USHORT m) // mod 2^m
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "mod2", 0, __LINE__);

  err = mod2_l (n_l, m, n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      default:
        panic (E_LINT_ERR, "mod2", err, __LINE__);
    }

  return *this;
}*/


const LINT& LINT::madd (const LINT& ln, const LINT& m)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "madd", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "madd", 1, __LINE__);
  if (m.status == E_LINT_INV) panic (E_LINT_INV, "madd", 2, __LINE__);

  err = madd_l (n_l, ln.n_l, n_l, m.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "madd", 2, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "madd", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::msub (const LINT& ln, const LINT& m)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "msub", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "msub", 1, __LINE__);
  if (m.status == E_LINT_INV) panic (E_LINT_INV, "msub", 2, __LINE__);

  err = msub_l (n_l, ln.n_l, n_l, m.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "msub", 2, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "msub", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::mmul (const LINT& ln, const LINT& m)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "mmul", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "mmul", 1, __LINE__);
  if (m.status == E_LINT_INV) panic (E_LINT_INV, "mmul", 2, __LINE__);

  if (&ln == this)
      err = msqr_l (n_l, n_l, m.n_l);
  else
      err = mmul_l (n_l, ln.n_l, n_l, m.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "mmul", 2, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "mmul", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::msqr (const LINT& m)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "msqr", 0, __LINE__);
  if (m.status == E_LINT_INV) panic (E_LINT_INV, "msqr", 1, __LINE__);

  err = msqr_l (n_l, n_l, m.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "msqr", 1, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "msqr", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::mexp (const USHORT e, const LINT& m)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "mexp", 0, __LINE__);
  if (m.status == E_LINT_INV) panic (E_LINT_INV, "mexp", 1, __LINE__);

  if (m.isodd ())
    {
      err = umexpm_l (n_l, e, n_l, m.n_l);
    }
  else
    {
      err = umexp_l (n_l, e, n_l, m.n_l);
    }

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "mexp", 2, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "mexp", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::mexp (const LINT& ln, const LINT& m)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "mexp", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "mexp", 1, __LINE__);
  if (m.status == E_LINT_INV) panic (E_LINT_INV, "mexp", 2, __LINE__);

  err = mexp_l (n_l, ln.n_l, n_l, m.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "mexp", 2, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "mexp", err, __LINE__);
    }

  return *this;
}




const LINT& LINT::mexpkm (const LINT& ln, const LINT& m)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "mexpkm", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "mexpkm", 1, __LINE__);
  if (m.status == E_LINT_INV) panic (E_LINT_INV, "mexpkm", 2, __LINE__);

  err = mexpkm_l (n_l, ln.n_l, n_l, m.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_MOD:
        panic (E_LINT_MOD, "mexpkm", 2, __LINE__);
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "mexpkm", 2, __LINE__);
        break;
      default:
        panic (E_LINT_ERR, "mexpkm", err, __LINE__);
    }

  return *this;
}




const LINT& LINT::shift (const int noofbits)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "shift", 0, __LINE__);

  err = shift_l (n_l, noofbits);

  switch (err)
    {
      case E_CLINT_OK:
        status = E_LINT_OK;
        break;
      case E_CLINT_OFL:
        status = E_LINT_OFL;
        break;
      case E_CLINT_UFL:
        status = E_LINT_UFL;
        break;
      default:
        panic (E_LINT_ERR, "shift", err, __LINE__);
    }

  return *this;
}


////////////////////////////////////////////////////////////////////////////////
//           Number-theoretic member functions                                //
////////////////////////////////////////////////////////////////////////////////


const unsigned int LINT::ld (void) const
{
  if (status == E_LINT_INV) panic (E_LINT_INV, "ld", 0, __LINE__);
  return ld_l (n_l);
}


const int LINT::iseven (void) const
{
  if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "iseven", 0, __LINE__);
  return (ISEVEN_L (n_l)); //lint !e613
}


const int LINT::isodd (void) const
{
  if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "isodd", 0, __LINE__);
  return (ISODD_L (n_l)); //lint !e613
}


const int LINT::isprime (const int noofsmallprimes, const int iterations) const
{
  if (status == E_LINT_INV) panic (E_LINT_INV, "isprime", 0, __LINE__);
  return (prime_l (n_l, noofsmallprimes, iterations));
}






const LINT LINT::gcd (const LINT& b) const
{
  LINT gcdiv;
  if (status == E_LINT_INV) panic (E_LINT_INV, "gcd", 0, __LINE__);
  if (b.status == E_LINT_INV) panic (E_LINT_INV, "gcd", 1, __LINE__);

  gcd_l (n_l, b.n_l, gcdiv.n_l);
  gcdiv.status = E_LINT_OK;

  return gcdiv;
}



const LINT LINT::xgcd (const LINT& b , LINT& u, int& sign_u, LINT& v, int& sign_v) const
{
  LINT g, hlp;
  if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "xgcd", 0, __LINE__);
  if (b.status == E_LINT_INV) LINT::panic (E_LINT_INV, "xgcd", 1, __LINE__);

  xgcd_l (n_l, b.n_l, g.n_l, u.n_l, &sign_u, v.n_l, &sign_v);
  g.status = E_LINT_OK;
  u.status = E_LINT_OK;
  v.status = E_LINT_OK;

  return g;
}


const LINT LINT::inv (const LINT& b) const
{
  LINT invers, hlp;
  if (status == E_LINT_INV) panic (E_LINT_INV, "inv", 0, __LINE__);
  if (b.status == E_LINT_INV) panic (E_LINT_INV, "inv", 1, __LINE__);

  inv_l (n_l, b.n_l, hlp.n_l, invers.n_l);
  invers.status = E_LINT_OK;

  return invers;
}




const int LINT::twofact (LINT& odd) const
{
  if (status == E_LINT_INV) panic (E_LINT_INV, "twofact", 0, __LINE__);
  odd.status = E_LINT_OK;
  return (twofact_l (n_l, odd.n_l));
}


const int LINT::mequ (const LINT& b, const LINT& m) const
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "mequ", 0, __LINE__);
  if (b.status == E_LINT_INV) panic (E_LINT_INV, "mequ", 1, __LINE__);
  if (m.status == E_LINT_INV) panic (E_LINT_INV, "mequ", 2, __LINE__);

  err = mequ_l (n_l, b.n_l, m.n_l);

  switch (err)
    {
      case 0:
      case 1:
        break;
      case E_CLINT_DBZ:
        panic (E_LINT_DBZ, "mequ", 2, __LINE__);
        break;
      default:
        LINT::panic (E_LINT_ERR, "mequ", err, __LINE__);
    }

  return err;
}



////////////////////////////////////////////////////////////////////////////////
//          Arithmetic friend functions                                       //
////////////////////////////////////////////////////////////////////////////////

const LINT add (const LINT& a, const LINT& b)
{
  LINT sum;
  int err;
  if (a.status == E_LINT_INV) LINT::panic (E_LINT_INV, "add", 1, __LINE__);
  if (b.status == E_LINT_INV) LINT::panic (E_LINT_INV, "add", 2, __LINE__);

  err = add_l (a.n_l, b.n_l, sum.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        sum.status = E_LINT_OK;
        break;
      case E_CLINT_OFL:
        sum.status = E_LINT_OFL;
        break;
      default:
        LINT::panic (E_LINT_ERR, "add", err, __LINE__);
    }

  return sum;
}


const LINT sub (const LINT& a, const LINT& b)
{
  LINT dif;
  int err;
  if (a.status == E_LINT_INV) LINT::panic (E_LINT_INV, "sub", 1, __LINE__);
  if (b.status == E_LINT_INV) LINT::panic (E_LINT_INV, "sub", 2, __LINE__);

  err = sub_l (a.n_l, b.n_l, dif.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        dif.status = E_LINT_OK;
        break;
      case E_CLINT_UFL:
        dif.status = E_LINT_UFL;
        break;
      default:
        LINT::panic (E_LINT_ERR, "sub", err, __LINE__);
    }

  return dif;
}


const LINT mul (const LINT& a, const LINT& b)
{
  LINT p;
  int err;
  if (a.status == E_LINT_INV) LINT::panic (E_LINT_INV, "mul", 1, __LINE__);
  if (b.status == E_LINT_INV) LINT::panic (E_LINT_INV, "mul", 2, __LINE__);

  if (&a == &b) //lint !e506
      err = sqr_l (a.n_l, p.n_l);
  else
      err = mul_l (a.n_l, b.n_l, p.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        p.status = E_LINT_OK;
        break;
      case E_CLINT_OFL:
        p.status = E_LINT_OFL;
        break;
      default:
        LINT::panic (E_LINT_ERR, "mul", err, __LINE__);
    }

  return p;
}


const LINT sqr (const LINT& a)
{
  LINT p;
  int err;
  if (a.status == E_LINT_INV) LINT::panic (E_LINT_INV, "sqr", 1, __LINE__);

  err = sqr_l (a.n_l, p.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        p.status = E_LINT_OK;
        break;
      case E_CLINT_OFL:
        p.status = E_LINT_OFL;
        break;
      default:
        LINT::panic (E_LINT_ERR, "sqr", err, __LINE__);
    }

  return p;
}


const LINT divr (const LINT& a, const LINT& b, LINT& r)
{
  LINT q;
  int err;
  if (a.status == E_LINT_INV) LINT::panic (E_LINT_INV, "divr", 1, __LINE__);
  if (b.status == E_LINT_INV) LINT::panic (E_LINT_INV, "divr", 2, __LINE__);

  err = div_l (a.n_l, b.n_l, q.n_l, r.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        q.status = E_LINT_OK;
        r.status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:
        LINT::panic (E_LINT_DBZ, "divr", 2, __LINE__);
        break;
      default:
        LINT::panic (E_LINT_ERR, "div", err, __LINE__);
    }

  return q;
}


const LINT mod (const LINT& a, const LINT& n)
{
  LINT r, junk;
  int err;
  if (a.status == E_LINT_INV)  LINT::panic (E_LINT_INV, "mod", 1, __LINE__);
  if (n.status == E_LINT_INV) LINT::panic (E_LINT_INV, "mod", 2, __LINE__);

  err = div_l (a.n_l, n.n_l, junk.n_l, r.n_l);

  switch (err)
    {
      case E_CLINT_OK:
        r.status = E_LINT_OK;
        break;
      case E_CLINT_DBZ:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -