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

📄 flintpp.cpp

📁 flint库 RSA算法
💻 CPP
📖 第 1 页 / 共 5 页
字号:

const LINT& LINT::operator++ (void) // Prefix operation
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "++", 0, __LINE__);

  err = inc_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, "++", err, __LINE__);
    }

  return *this;
}


const LINT LINT::operator++ (int i) // Postfix operation
{
  LINT tmp = *this;
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "++", 0, __LINE__);

  err = inc_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, "++", err, __LINE__);
    }

  return tmp;
} //lint !e715


const LINT& LINT::operator-- (void) // Prefix operation
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "--", 0, __LINE__);

  err = dec_l (n_l);

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

  return *this;
}


const LINT LINT::operator-- (int i) // Postfix operation
{
  LINT tmp = *this;
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "--", 0, __LINE__);

  err = dec_l (n_l);

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

  return tmp;
} //lint !e715


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

  err = add_l (n_l, ln.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, "+=", err, __LINE__);
    }

  return *this;
}


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

  err = sub_l (n_l, ln.n_l, n_l);

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

  return *this;
}


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

  if (&ln == this)
      err = sqr_l (n_l, n_l); // Use squaring function sqr_l for ln*=ln
  else
      err = mul_l (n_l, ln.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, "*=", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::operator/= (const LINT& ln)
{
  CLINT junk_l;
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "/=", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "/=", 1, __LINE__);

  err = div_l (n_l, ln.n_l, n_l, junk_l);

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

  ZEROCLINT_L (junk_l);
  return *this;
}


const LINT& LINT::operator%= (const LINT& ln)
{
  CLINT junk_l;
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "%=", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "%=", 1, __LINE__);

  err = div_l (n_l, ln.n_l, junk_l, n_l);

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

  ZEROCLINT_L (junk_l);
  return *this;
}


// Bitwise operators


const LINT operator<< (const LINT& ln, int times)
{
  int err;
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "<<", 1, __LINE__);
  LINT shft = ln;

  err = shift_l (shft.n_l, times);

  switch (err)
    {
      case E_CLINT_OK:
        shft.status = E_LINT_OK;  // status = E_LINT_OK is set
        break;                    // because shft = ln was executed in advance
      case E_CLINT_OFL:
        shft.status = E_LINT_OFL;
        break;
      case E_CLINT_UFL:
        shft.status = E_LINT_UFL;
        break;
      default:
        LINT::panic (E_LINT_ERR, "<<", err, __LINE__);
    }

  return shft;
}


const LINT operator>> (const LINT& ln, int times)
{
  int err;
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, ">>", 1, __LINE__);
  LINT shft = ln;

  err = shift_l (shft.n_l, -times);

  switch (err)
    {
      case E_CLINT_OK:
        shft.status = E_LINT_OK;  // status = E_LINT_OK is set
        break;                    // because shft = ln was executed in advance
      case E_CLINT_OFL:
        shft.status = E_LINT_OFL;
        break;
      case E_CLINT_UFL:
        shft.status = E_LINT_UFL;
        break;
      default:
        LINT::panic (E_LINT_ERR, ">>", err, __LINE__);
    }

  return shft;
}


const LINT& LINT::operator<<= (int times)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, "<<=", 0, __LINE__);

  err = shift_l (n_l, times);

  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, "<<=", err, __LINE__);
    }

  return *this;
}


const LINT& LINT::operator>>= (int times)
{
  int err;
  if (status == E_LINT_INV) panic (E_LINT_INV, ">>=", 0, __LINE__);

  err = shift_l (n_l, -times);

  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, ">>=", err, __LINE__);
    }

  return *this;
}


const LINT operator^ (const LINT& lm, const LINT& ln)
{
  LINT lr;
  if (lm.status == E_LINT_INV) LINT::panic (E_LINT_INV, "^", 1, __LINE__);
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "^", 2, __LINE__);

  xor_l (lm.n_l, ln.n_l, lr.n_l);

  lr.status = E_LINT_OK;
  return lr;
}


const LINT operator| (const LINT& lm, const LINT& ln)
{
  LINT lr;
  if (lm.status == E_LINT_INV) LINT::panic (E_LINT_INV, "|", 0, __LINE__);
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "|", 1, __LINE__);

  or_l (lm.n_l, ln.n_l, lr.n_l);

  lr.status = E_LINT_OK;
  return lr;
}


const LINT operator& (const LINT& lm, const LINT& ln)
{
  LINT lr;
  if (lm.status == E_LINT_INV) LINT::panic (E_LINT_INV, "&", 1, __LINE__);
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "&", 2, __LINE__);

  and_l (lm.n_l, ln.n_l, lr.n_l);

  lr.status = E_LINT_OK;
  return lr;
}


const LINT& LINT::operator|= (const LINT& ln)
{
  if (status == E_LINT_INV) panic (E_LINT_INV, "|=", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "|=", 1, __LINE__);

  or_l (n_l, ln.n_l, n_l);

  status = E_LINT_OK;
  return *this;
}


const LINT& LINT::operator&= (const LINT& ln)
{
  if (status == E_LINT_INV) panic (E_LINT_INV, "&=", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "&=", 1, __LINE__);

  and_l (n_l, ln.n_l, n_l);

  status = E_LINT_OK;
  return *this;
}


const LINT& LINT::operator^= (const LINT& ln)
{
  if (status == E_LINT_INV) panic (E_LINT_INV, "^=", 0, __LINE__);
  if (ln.status == E_LINT_INV) panic (E_LINT_INV, "^=", 1, __LINE__);

  xor_l (n_l, ln.n_l, n_l);
  status = E_LINT_OK;
  return *this;
}


////////////////////////////////////////////////////////////////////////////////
//           Logical operators as friend functions                            //
////////////////////////////////////////////////////////////////////////////////

const int operator== (const LINT& lm, const LINT& ln)
{
  if (lm.status == E_LINT_INV) LINT::panic (E_LINT_INV, "==", 1, __LINE__);
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "==", 2, __LINE__);

  if (&lm == &ln)       //lint !e506
    {
      return 1;
    }

  return equ_l (lm.n_l, ln.n_l);
  // Operator == returns 1 if lm == ln, 0 else
}


const int operator!= (const LINT& lm, const LINT& ln)
{
  if (lm.status == E_LINT_INV) LINT::panic (E_LINT_INV, "!=", 1, __LINE__);
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "!=", 2, __LINE__);

  if (&lm == &ln)       //lint !e506
    {
      return 0;
    }

  return (equ_l (lm.n_l, ln.n_l) == 0);
  // Operator != returns 1 if lm != ln, 0 else
}


const int operator< (const LINT& lm, const LINT& ln)
{
  if (lm.status == E_LINT_INV)  LINT::panic (E_LINT_INV, "<", 1, __LINE__);
  if (ln.status == E_LINT_INV)  LINT::panic (E_LINT_INV, "<", 2, __LINE__);

  if (&lm == &ln)       //lint !e506
    {
      return 0;
    }

  return (cmp_l (lm.n_l, ln.n_l) == -1);
}


const int operator> (const LINT& lm, const LINT& ln)
{
  if (lm.status == E_LINT_INV)  LINT::panic (E_LINT_INV, ">", 1, __LINE__);
  if (ln.status == E_LINT_INV)  LINT::panic (E_LINT_INV, ">", 2, __LINE__);

  if (&lm == &ln)       //lint !e506
    {
      return 0;
    }

  return (cmp_l (lm.n_l, ln.n_l) == 1);
}


const int operator<= (const LINT& lm, const LINT& ln)
{
  int i;
  if (lm.status == E_LINT_INV)  LINT::panic (E_LINT_INV, "<=", 1, __LINE__);
  if (ln.status == E_LINT_INV)  LINT::panic (E_LINT_INV, "<=", 2, __LINE__);

  if (&lm == &ln)       //lint !e506
    {
      return 1;
    }

  i = cmp_l (lm.n_l, ln.n_l);
  return ((i == -1) || (i == 0));
}


const int operator>= (const LINT& lm, const LINT& ln)
{
  int i;
  if (lm.status == E_LINT_INV)  LINT::panic (E_LINT_INV, ">=", 1, __LINE__);
  if (ln.status == E_LINT_INV)  LINT::panic (E_LINT_INV, ">=", 2, __LINE__);

  if (&lm == &ln)       //lint !e506
    {
      return 1;
    }

  i = cmp_l (lm.n_l, ln.n_l);
  return ((i == 1) || (i == 0));
}


////////////////////////////////////////////////////////////////////////////////
//           Bit access with member functions                                 //
////////////////////////////////////////////////////////////////////////////////

const LINT& LINT::setbit (unsigned int pos)
{
  int err;
  if (status == E_LINT_INV)
    { // If not initialized, set *this to 0 !
      SETZERO_L (n_l);
      status = E_LINT_OK;
    }

  err = setbit_l (n_l, pos);

  switch (err)
    {
      case E_CLINT_OFL:
        status = E_LINT_OFL;
        break;
      default:
	break; // do nothing
    }

  return *this;
}


const LINT& LINT::clearbit (unsigned int pos)
{
  if (status == E_LINT_INV) panic (E_LINT_INV, "clearbit()", 0, __LINE__);

  clearbit_l (n_l, pos);

  status = E_LINT_OK;
  return *this;
}


int LINT::testbit (unsigned int pos) const
{
  if (status == E_LINT_INV) panic (E_LINT_INV, "testbit()", 0, __LINE__);

⌨️ 快捷键说明

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