diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-06-09 14:42:12 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-06-09 14:42:12 +0200 |
| commit | 9d7c264a6579cddcad12f9185475af89a9a59b41 (patch) | |
| tree | c2b421bd7b4b45aae3767a164c70af7ffac76961 /src/crypt/cbigint.h | |
| parent | 672ebc3868997c44b83f7afe59e9b4d876135247 (diff) | |
| download | IT-Sicherheit-9d7c264a6579cddcad12f9185475af89a9a59b41.tar.gz IT-Sicherheit-9d7c264a6579cddcad12f9185475af89a9a59b41.zip | |
Add CBigInt skeleton
Diffstat (limited to 'src/crypt/cbigint.h')
| -rw-r--r-- | src/crypt/cbigint.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/crypt/cbigint.h b/src/crypt/cbigint.h new file mode 100644 index 0000000..f4ea407 --- /dev/null +++ b/src/crypt/cbigint.h @@ -0,0 +1,98 @@ +#ifndef CBIGINT_H +#define CBIGINT_H + +/** + * An integer number with unlimited number of digits. Low digit is at low address. + * + * @author Walter Roth + */ + +//define the base type of the number here. Useable types are: char, short int +typedef char BaseType; +struct BaseStruct +{ + BaseType low; + BaseType high; +}; + +union LongBaseType +{ + short int allSegments; + BaseStruct Segment; +}; + +class CBigInt +{ +public: + /** + * Default constructor. Creates a number with size zero digits. + * Converts value to it's CbigInt representation. + */ + CBigInt(int value = 0); + + /** + * Copy constructor. Creates a deep copy. + */ + CBigInt(const CBigInt & toCopy); + + /** + * Destructor frees memory. + */ + ~CBigInt(); + + /** + * Sets the new size, allocates memory and initializes with 0. + * If newSize is smaller than old,* _Size is reduced as long as + * digits to delete are zero. Returns final size. + */ + int setSize(int newSize); + + /** + * Returns the number of digits available (_Size) + */ + int size() const; + + /** + * Sets digit at position to value + */ + void setDigit(int pos, BaseType value); + + /** + * Operator + + */ + CBigInt operator +(const CBigInt & n2); + + /** + * Returns the number as a hexadecimal string + */ + const char * toHexString()const; + + /** + * Returns true, if LongBaseType is twice the size of BaseType + */ + static bool isLongOk(); + +private: + /** + * Make a deep copy + */ + void copy(const CBigInt & toCopy); + +private: + /** + * The start of the digit-array. Points to LSB. + */ + BaseType * _Digits; + + /** + * The number of Digits allocated. + */ + int _Size; + + /** + * The string buffer for toXXString functions + */ + static char * _StringBuffer; +} + +#endif // CBIGINT_H |
