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

📄 flintpp.h

📁 rsa算法的c++实现,该程序实现利用私钥解密
💻 H
📖 第 1 页 / 共 2 页
字号:
  // Export as CLINT type

  friend clint* lint2clint (const LINT& ln);

  // Overloading of ostream insert operator << for LINT-objects

  friend ostream& operator<< (ostream& s, const LINT& ln);

  // Overloading of fstream/istream/ofstream insert operators >>,<<
  // for file-IO of LINT objects

  friend fstream& operator<< (fstream& s, const LINT& ln);
  friend ofstream& operator<< (ofstream& s, const LINT& ln);

  friend fstream& operator>> (fstream& s, LINT& ln);
  friend ifstream& operator>> (ifstream& s, LINT& ln);


  // LINT-MEMBERS

  // Constructors

  LINT (void);                               // Constructor  1
  LINT (const char* const, const int);       // Constructor  2
  LINT (const UCHAR* const, const int);      // Constructor  3
  LINT (const char* const);                  // Constructor  4
  LINT (const LINT&);                        // Constructor  5  (Copy)
  LINT (const signed int);                   // Constructor  6
  LINT (const signed long);                  // Constructor  7
  LINT (const unsigned char);                // Constructor  8
  LINT (const unsigned short);               // Constructor  9
  LINT (const unsigned int);                 // Constructor 10
  LINT (const unsigned long);                // Constructor 11
  LINT (const CLINT);                        // Constructor 12

  //  Destructor

  ~LINT (void)
    {
#ifdef FLINT_SECURE
      purge_l (n_l);
#endif // FLINT_SECURE
      delete [] n_l;
    }


  // Overloaded operators, implemented as member functions
  // left (implicit) argument is always of type LINT

  // Assignment

  const LINT& operator= (const LINT&);

  // Arithmetic

  const LINT& operator++ (void);
  const LINT operator++ (int);
  const LINT& operator-- (void);
  const LINT operator-- (int);
  const LINT& operator+= (const LINT&);
  const LINT& operator-= (const LINT&);
  const LINT& operator*= (const LINT&);
  const LINT& operator/= (const LINT&);
  const LINT& operator%= (const LINT&);

  // Bitwise and Boolean functions

  const LINT& operator<<= (const int);
  const LINT& operator>>= (const int);
  const LINT& operator^= (const LINT&);
  const LINT& operator|= (const LINT&);
  const LINT& operator&= (const LINT&);

  // Member functions
  // Arithmetic

  const LINT& add (const LINT&);
  const LINT& sub (const LINT&);
  const LINT& mul (const LINT&);
  const LINT& sqr (void);
  const LINT& divr (const LINT&, LINT&);
  const LINT& mod (const LINT&);
  //const LINT& mod2 (const USHORT);

  // Modular arithmetic

  const LINT& madd (const LINT&, const LINT&);
  const LINT& msub (const LINT&, const LINT&);
  const LINT& mmul (const LINT&, const LINT&);
  const LINT& msqr (const LINT&);
  const LINT& mexp (const LINT&, const LINT&);
  const LINT& mexp (const USHORT, const LINT&);
  const LINT& mexpkm (const LINT&, const LINT&);
  const LINT& shift (const int);

  // Number theoretic member Funktionen

  const LINT gcd (const LINT&) const;
  const LINT xgcd (const LINT&, LINT&, int&, LINT&, int&) const;
  const LINT inv (const LINT&) const;
  const int twofact (LINT&) const;
  const unsigned int ld (void) const;
  const int isprime (const int noofsmallprimes = 302, const int iterations = 0) const;
  const LINT issqr (void) const;
  const int mequ (const LINT&, const LINT&) const;
   const int iseven (void) const;
  const int isodd (void) const;


  // Bit-access

  const LINT& setbit (const unsigned int);
  
  // Swapping

  LINT& fswap (LINT&);

  // Purging of LINT-variables, overwriting with 0

  void purge (void);


  // Conversion & Input/Output

  enum {
      lintdec        = 0x010,
      lintoct        = 0x020,
      linthex        = 0x040,
      lintshowbase   = 0x080,
      lintuppercase  = 0x100,
      lintbin        = 0x200,
      lintshowlength = 0x400
  };

  static long flags (void);
  static long flags (ostream&);
  static long setf (long int);
  static long setf (ostream&, long int);
  static long unsetf (long int);
  static long unsetf (ostream&, long int);
  static long restoref (long int);
  static long restoref (ostream&, long int);


  // LINT-to-string conversion

  inline char* hexstr (void) const
    {
      return lint2str (16);
    }
  inline char* decstr (void) const
    {
      return lint2str (10);
    }
  inline char* octstr (void) const
    {
      return lint2str (8);
    }
  inline char* binstr (void) const
    {
      return lint2str (2);
    }

  // Conversion to string and bytevector

  char* lint2str (const USHORT, const int = 0) const;
  UCHAR* lint2byte (int*) const;

  // Export as CLINT type

  clint* lint2clint (void) const;

  // preformatted output

  inline void disp (char* str)
    {
      cout << str << lint2str (16) << endl << ld () << " bit\n";
    }


  // Set user-defined error handler

  static void Set_LINT_Error_Handler (void (*)(LINT_ERRORS, const char* const, const int, const int));

  //Get Error/Warning-Status

  LINT_ERRORS Get_Warning_Status (void);
  clint* keyvalue () { return n_l;};

 private:
  // Pointer to type CLINT
  clint* n_l;

  // Status after an operation on a LINT object
  LINT_ERRORS status;

  // LINT::Default-Error-Handler
  static void panic (LINT_ERRORS, const char* const, const int, const int);

  // Dummy object of class LintInit
  static LintInit setup;

  // Pointer to ios flag register to be allocated
   static long flagsindex;
};

// CLASS LINT ends
///////////////////////////////////////////////////////////////////////////////




// Some auxiliary functions for LINT manipulators

// ostream format functions
ostream& _SetLintFlags (ostream& , int);
ostream& _ResetLintFlags (ostream& , int);

// Container-class LINT_omanip
template <class T>
class LINT_omanip
{
 public:
  LINT_omanip (ostream&(*g)(ostream&, T), T j): i(j), f(g) {}
  friend ostream& operator <<(ostream& os, const LINT_omanip<T>& m)
    {
      return (*m.f) (os, m.i);
    }

 protected:
  T i;
  ostream& (*f)(ostream&, T);
}; //lint !e1712  Don't complain about missing default constructor


// Manipulators for output format of LINT objects

LINT_omanip <int> SetLintFlags (int);
LINT_omanip <int> ResetLintFlags (int);

ostream& LintHex (ostream&);
ostream& LintDec (ostream&);
ostream& LintOct (ostream&);
ostream& LintBin (ostream&);
ostream& LintUpr (ostream&);
ostream& LintLwr (ostream&);
ostream& LintShowbase (ostream&);
ostream& LintNobase (ostream&);
ostream& LintShowlength (ostream&);
ostream& LintNolength (ostream&);


// Templates for platform-independent writing and reading of USHORT values

template <class T>
int read_ind_ushort (T& s, clint* dest)
{
  UCHAR buff[sizeof (clint)];
  unsigned i;
  s.read ((char*)buff, sizeof (clint));

  if (!s)
    {
      return -1;
    }
  else
    {
      *dest = 0;
      for (i = 0; i < sizeof (clint); i++)
        {
          *dest |= ((clint)buff[i]) << (i << 3);
        }
      return 0;
    }
}


template <class T>
int write_ind_ushort (T& s, clint src)
{
  UCHAR buff[sizeof (clint)];
  unsigned i, j;
  for (i = 0, j = 0; i < sizeof (clint); i++, j = i << 3)
    {
      buff[i] = (UCHAR)((src & (0xff << j)) >> j);
    }
  s.write ((const char*)buff, sizeof (clint));
  if (!s)
    {
      return -1;
    }
  else
    {
      return 0;
    }
}


// min, max as template-inline-functions
// (Acc. Scott Meyers,"Effective C++", 2nd. Ed. Addison-Wesley 1998)
// min und max should be present in  C++-Standard Template Library, but...

#if !defined FLINTPP_ANSI || (defined __IBMCPP__ && (__IBMCPP__ <=300)) || (defined _MSC_VER && (_MSC_VER <= 1200)) || defined __WATCOMC__

#ifndef min
template <class T>
inline const T& min (const T& a, const T& b)
{ return a < b ? a : b; }
#endif // min

#ifndef max
template <class T>
inline const T& max (const T& a, const T& b)
{ return a > b ? a : b; }
#endif // max
#endif // !(defined __IBMCPP__ || defined FLINTPP_ANSI)


#endif // __FLINTPPH__







⌨️ 快捷键说明

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