vlong.cpp in RSA_file_encryption.
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.