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

📄 flintpp.cpp

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

  return random;
}

////////////////////////////////////////////////////////////////////////////////
//                         Input/Output                                       //
////////////////////////////////////////////////////////////////////////////////


long LINT::flagsindex;

// Initialization of class member setup (class LintStatus == E_LINT_INV)
// The initialization of LINT::setup causes a call to the constructor 
// LintInit(), which in turn initializes the static member flagsindex as 
// a pointer to ios-internal memory: 

LintInit LINT::setup; /*lint !e1502*/


// Constructor LintInit() sets the ios-internal variable ios::iword (flagsindex)
// to the LINT default values:

LintInit::LintInit (void)
{
  // Get index to status variable of type long in class ios
  LINT::flagsindex = ios::xalloc ();

  // Set default status in cout and cerr
  cout.iword (LINT::flagsindex) = cerr.iword (LINT::flagsindex) =
           LINT::lintshowlength | LINT::linthex | LINT::lintshowbase;
}


// Read static LINT status variable in ios for standard output stream cout

long LINT::flags (void)
{
  return cout.iword (flagsindex);
}


// Read static LINT status variable in ios for output stream ostream s

long LINT::flags (ostream& s)
{
  return s.iword (flagsindex);
}


// Set static LINT status variable in ios for output stream ostream s

long LINT::setf (ostream& s, long flag)
{
  long t = s.iword (flagsindex);

  // Flags lintdec, linthex, lintbin, lintoct are mutually exclusive:
  if (flag & LINT::lintdec)
    {
      s.iword (flagsindex) = 
        (t & ~LINT::linthex & ~LINT::lintoct & ~LINT::lintbin) | LINT::lintdec;
      flag ^= LINT::lintdec;
    }

  if (flag & LINT::linthex)
    {
      s.iword (flagsindex) =
        (t & ~LINT::lintdec & ~LINT::lintoct & ~LINT::lintbin) | LINT::linthex;
      flag ^= LINT::linthex;
    }

  if (flag & LINT::lintoct)
    {
      s.iword (flagsindex) = 
        (t & ~LINT::lintdec & ~LINT::linthex & ~LINT::lintbin) | LINT::lintoct;
      flag ^= LINT::lintoct;
    }
  
  if (flag & LINT::lintbin)
    {
      s.iword (flagsindex) = 
        (t & ~LINT::lintdec & ~LINT::lintoct & ~LINT::linthex) | LINT::lintbin;
      flag ^= LINT::lintbin;
    } 

  // All remaining flags are mutually compatible:
  s.iword (flagsindex) |= flag;

  return t;
}


// Set static LINT status variable in ios for standard output stream cout

long LINT::setf (long flag)
{
  return LINT::setf (cout, flag);
}


// Switch off status bits in ostream s

long LINT::unsetf (ostream& s, long flag)
{
  int t = s.iword (flagsindex);
  s.iword (flagsindex) = (t | flag) ^ flag;
  return t;
}


// Switch off status bits in stream cout

long LINT::unsetf (long flag)
{
  return LINT::unsetf (cout, flag);
}


// Reset of LINT status variable for stream ostream s

long LINT::restoref (ostream& s, long flag)
{
  int t = s.iword (flagsindex);
  LINT::unsetf (s, t);
  s.iword (flagsindex) = flag;
  return t;
}


// Reset of LINT status variable for standard stream ostream cout

long LINT::restoref (long flag)
{
  return LINT::restoref (cout, flag);
}


// Manipulators

ostream& LintHex (ostream& s)
{
  LINT::setf (s, LINT::linthex);
  return s;
}

ostream& LintDec (ostream& s)
{
  LINT::setf (s, LINT::lintdec);
  return s;
}

ostream& LintOct (ostream& s)
{
  LINT::setf (s, LINT::lintoct);
  return s;
}

ostream& LintBin (ostream& s)
{
  LINT::setf (s, LINT::lintbin);
  return s;
}

ostream& LintUpr (ostream& s)
{
  LINT::setf (s, LINT::lintuppercase);
  return s;
}

ostream& LintLwr (ostream& s)
{
  LINT::unsetf (s, LINT::lintuppercase);
  return s;
}

ostream& LintShowbase (ostream& s)
{
  LINT::setf (s, LINT::lintshowbase);
  return s;
}

ostream& LintNobase (ostream& s)
{
  LINT::unsetf (s, LINT::lintshowbase);
  return s;
}

ostream& LintShowlength (ostream& s)
{
  LINT::setf (s, LINT::lintshowlength);
  return s;
}

ostream& LintNolength (ostream& s)
{
  LINT::unsetf (s, LINT::lintshowlength);
  return s;
}


// Manipulators SetLintFlags, ResetLintFlags

ostream& _SetLintFlags (ostream& s, int flag)
{
  LINT::setf (s, flag);
  return s;
}

ostream& _ResetLintFlags (ostream& s, int flag)
{
  LINT::unsetf (s, flag);
  return s;
}

LINT_omanip <int> SetLintFlags (int flag)
{
  return LINT_omanip <int> (&_SetLintFlags, flag);
}

LINT_omanip <int> ResetLintFlags (int flag)
{
  return LINT_omanip <int> (&_ResetLintFlags, flag);
}


// Overloading of ostream operator << for ouput of LINT objects

ostream& operator << (ostream& s, const LINT& ln)
{
  unsigned short base = 16;
  long flags = LINT::flags (s);
  char* formatted_lint;

  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "ostream operator<<", 0, __LINE__);

  if (flags & LINT::linthex)
    {
      base = 16;
    }
  else
    {
      if (flags & LINT::lintdec)
        {
          base = 10;
        }
      else
        {
          if (flags & LINT::lintoct)
            {
              base = 8;
            }
          else
            {
              if (flags & LINT::lintbin)
                {
                  base = 2;
                }
            }
        }
    }
 
  if (flags & LINT::lintshowbase)
    {
      formatted_lint = lint2str (ln, base, 1);
    }
  else
    {
      formatted_lint = lint2str (ln, base, 0);
    }

  if (flags & LINT::lintuppercase)
    {
      strupr_l (formatted_lint);
    }

  s << formatted_lint << flush;

  if (flags & LINT::lintshowlength)
    {
      long _flags = s.flags ();  //get current flag settings
      s.setf (ios::dec);         //lint !e641
      s << endl << ld (ln) << " bit\n" << endl;
      s.setf (_flags);           //restore flags
    }

  return s;
}


// Overloading of ifstream/ofstream operators >>/<< for file input/ouput 
// of LINT objects

ofstream& operator<< (ofstream& s, const LINT& ln)
{
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "ofstream operator <<", 0, __LINE__);
  for (int i = 0; i <= (int) DIGITS_L (ln.n_l); i++)
    {
      if (write_ind_ushort (s, ln.n_l[i]))
        {
          LINT::panic (E_LINT_EOF, "ofstream operator <<", 0, __LINE__);
        }
    }
  return s;
}


fstream& operator<< (fstream& s, const LINT& ln)
{
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "fstream operator <<", 0, __LINE__);
  for (int i = 0; i <= (int) DIGITS_L (ln.n_l); i++)
    {
      if (write_ind_ushort (s, ln.n_l[i]))
        {
          LINT::panic (E_LINT_EOF, "fstream operator <<", 0, __LINE__);
        }
    }
  return s;
}


ifstream& operator>> (ifstream& s, LINT& ln)
{
  if (read_ind_ushort (s, ln.n_l))
    {
      LINT::panic (E_LINT_EOF, "ifstream operator >>", 0, __LINE__);
    }

  if (DIGITS_L (ln.n_l) < CLINTMAXSHORT)
    {
      for (int i = 1; i <= (int) DIGITS_L (ln.n_l); i++)
        {
          if (read_ind_ushort (s, &ln.n_l[i]))
            {
              LINT::panic (E_LINT_EOF, "ifstream operator >>", 0, __LINE__);
            }
        }
    }
  if (vcheck_l (ln.n_l) == 0)    // be paranoid - check imported values!
    {
      ln.status = E_LINT_OK;
    }
  else
    {
      ln.status = E_LINT_INV;
    }
  return s;
}


fstream& operator>> (fstream&s, LINT& ln)
{
  if (read_ind_ushort (s, ln.n_l))
    {
      LINT::panic (E_LINT_EOF, "fstream operator >>", 0, __LINE__);
    }

  if (DIGITS_L (ln.n_l) < CLINTMAXSHORT)
    {
      for (int i = 1; i <= (int) DIGITS_L (ln.n_l); i++)
        {
          if (read_ind_ushort (s, &ln.n_l[i]))
            {
              LINT::panic (E_LINT_EOF, "fstream operator >>", 0, __LINE__);
            }
        }
    }
  if (vcheck_l (ln.n_l) == 0)
    { // Be paranoid ...
      ln.status = E_LINT_OK;
    }
  else
    {
      ln.status = E_LINT_INV;
    }
  return s;
}


// Conversion of type LINT to character string by lint2str

// lint2str as member function:

char* LINT::lint2str (const USHORT base, const int showbase) const
{
  if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "lint2str", 0, __LINE__);
  return xclint2str_l (n_l, base, showbase);
}


// lint2str as friend function

char* lint2str (const LINT& ln, const USHORT  base, const int showbase)
{
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "lint2str", 0, __LINE__);
  return xclint2str_l (ln.n_l, base, showbase);
}


// Conversion of type LINT to byte array by lint2byte

// lint2byte as member function:

UCHAR* LINT::lint2byte (int* len) const
{
  if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "lint2byte", 0, __LINE__);
  return clint2byte_l (n_l, len);
}


// lint2byte as friend function

UCHAR* lint2byte (const LINT& ln, int* len)
{
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "lint2byte", 0, __LINE__);
  return clint2byte_l (ln.n_l, len);
}


// LINT to CLINT export

// lint2clint as member function:

clint* LINT::lint2clint (void) const
{
  if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "lint2clint", 0, __LINE__);
  return n_l;
}


// lint2clint as friend function

clint* lint2clint (const LINT& ln)
{
  if (ln.status == E_LINT_INV) LINT::panic (E_LINT_INV, "lint2clint", 0, __LINE__);
  return ln.n_l;
}


////////////////////////////////////////////////////////////////////////////////
//                         Error-Handling                                     //
////////////////////////////////////////////////////////////////////////////////

//Get error status

LINT_ERRORS LINT::Get_Warning_Status (void)
{
  return status;
}

//Set user defined error handler

static void (*LINT_User_Error_Handler)(LINT_ERRORS, const char* const, const int, const int) = NULL;

void LINT::Set_LINT_Error_Handler (void (*Error_Handler)(LINT_ERRORS,
                                     const char* const, const int, const int))
{
  LINT_User_Error_Handler = Error_Handler;
}


// Set default error handler (member function)

void LINT::panic (LINT_ERRORS error, const char* const func, const int arg, const int line)
{
  if (LINT_User_Error_Handler)
    {
      LINT_User_Error_Handler (error, func, arg, line);
    }
  else
    {
      cerr << "Critical runtime error detected by class LINT:\n";
      switch (error)
        {
          case E_LINT_OK:
            // O.K., do nothing
            break;

          case E_LINT_DBZ:
            cerr << "Division by zero, operator/function " << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_DivByZero (func, line);
#endif
            break;

          case E_LINT_EOF:
            cerr << "Error in file I/O, operator/function " << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_File (func, line);
#endif
            break;

          case E_LINT_OFL:
            cerr << "Overflow, operator/function " << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_OFL (func, line);
#endif
            break;

          case E_LINT_UFL:
            cerr << "Underflow, operator/function " << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_UFL (func, line);
#endif
            break;

          case E_LINT_NHP:
            cerr << "Error in new, function/operator " << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_Heap (func, line);
#endif
            break;

          case E_LINT_INV:
            cerr << "Argument " << arg << " in operator/function " << func;
            cerr << " uninitialized" << endl;
            cerr << "or has invalid value, line ";
            cerr << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_Init (func, arg, line);
#endif
            break;

          case E_LINT_BOR:
            cerr << "Base invalid, operator/function " << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_Base (func, line);
#endif
            break;

          case E_LINT_MOD:
            cerr << "Modulus is even, operator/function " << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_Emod (func, line);
#endif
            break;

          case E_LINT_NPT:
            cerr << "Argument " << arg << " is Null-pointer in operator/function" << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_Nullptr (func, arg, line);
#endif
            break;

          case E_LINT_ERR:
          default:
            cerr << "Unexpected Error in operator/function " << func;
            cerr << ", line " << line << ", module " << __FILE__ << endl;
#ifdef LINT_EX
            throw LINT_Mystic (func, arg, line);
#endif
        }
      abort ();
    }
}

///////////////////////////////////////////////////////////////////////////////
//   

⌨️ 快捷键说明

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