vlong.cpp in RSA_file_encryption.


RSA public key encryption algorithm will be applied to small-scale file encrypti...Original Link
    Sponsored links

			
#include "stdafx.h"
// very long integer - can be used like long
// this is a draft useful class:)
#include "vlong.h"

class vlong_value;

class flex_unit // Provides storage allocation and index checking
{
  unsigned * a; // array of units
  unsigned z; // units allocated
public:
  unsigned n; // used units (read-only)
  flex_unit();
  ~flex_unit();
  void clear(); // set n to zero
  unsigned get( unsigned i ) const;     // get ith unsigned
  void set( unsigned i, unsigned x );   // set ith unsigned
  void reserve( unsigned x );           // storage hint
  
  unsigned get_z(void) const;     // get allocated units count
  
  // Time critical routine
  void fast_mul( flex_unit &x, flex_unit &y, unsigned n );
};

class vlong_value : public flex_unit
{
  public:
  unsigned share; // share count, used by vlong to delay physical copying
  int is_zero() const;
  int test( unsigned i ) const;
  unsigned bits() const;
  int cf( vlong_value& x ) const;
  void shl();
  void shr();
  void shr( unsigned n );
  void add( vlong_value& x );
  void subtract( vlong_value& x );
  void init( unsigned x );
  void copy( vlong_value& x );
  operator unsigned(); // Unsafe conversion to unsigned
  vlong_value();
  void mul( vlong_value& x, vlong_value& y );
  void divide( vlong_value& x, vlong_value& y, vlong_value& rem );
};

unsigned flex_unit::get_z() const
{
  return z;
}

unsigned flex_unit::get( unsigned i ) const
{
  if ( i >= n ) return 0;
  return a[i];
}

void flex_unit::clear()
{
   n = 0;
}

flex_unit::flex_unit()
{
  z = 0;
  a = 0;
  n = 0;
}

flex_unit::~flex_unit()
{
  unsigned i=z;
  while (i) { i-=1; a[i] = 0; } // burn
  delete [] a;
}

void flex_unit::reserve( unsigned x )
{
  if (x > z)
  {
    unsigned * na = new unsigned[x];
    for (unsigned i=0;i<n;i+=1) na[i] = a[i];
    delete [] a;
    a = na;
    z = x;
  }
}

void flex_unit::set( unsigned i, unsigned x )
{
  if ( i < n )
  {
    a[i] = x;
    if (x==0) while (n && 			

			...
			...
			... to be continued.

  This is a preview. To get the complete source file, 
  please click here to download the whole source code package.

			
			


Project Files

    Sponsored links
NameSizeDate
 ReadMe.txt1,003.00 B18-01-06 12:31
 rsa_draft.cpp3.30 kB18-01-06 23:20
 rsa_draft.h522.00 B18-01-06 23:21
 rsa_san.cpp9.02 kB21-01-06 15:30
 rsa_san.h1.11 kB21-01-06 15:30
 sanpack_rsa.cpp2.92 kB23-01-06 11:43
 sanpack_rsa.h1.56 kB23-01-06 11:48
 stdafx.cpp215.00 B18-01-06 12:31
 stdafx.h263.00 B18-01-06 12:31
 vlong.cpp10.56 kB19-01-06 13:38
 vlong.h1.74 kB19-01-06 13:37
 ReadMe.txt1.04 kB19-01-06 15:14
 rsa_draft.cpp3.30 kB18-01-06 23:20
 rsa_draft.h522.00 B18-01-06 23:21
 rsa_san.cpp9.02 kB21-01-06 15:30
 rsa_san.h1.11 kB21-01-06 15:30
 sanpack_rsa.cpp2.92 kB23-01-06 11:43
 sanpack_rsa.h1.56 kB23-01-06 11:48
 sanpack_rsa_c_debug.cpp90.00 B19-01-06 15:20
 stdafx.cpp223.00 B19-01-06 15:14
 stdafx.h195.00 B19-01-06 15:14
 vlong.cpp10.56 kB19-01-06 13:38
 vlong.h1.74 kB19-01-06 13:37
 <sanpack_rsa>0.00 B24-04-08 09:20
 <sanpack_rsa_c_debug>0.00 B24-04-08 09:21
 <RSA_file_encryption_wangyuqing>0.00 B22-04-09 08:21
...

Related Items

    Sponsored links