class AConverto : public ABase | |
---|---|
This object is a conversion object. It provides utility methods to allow encoding, decoding, CRC generation, and such. This object is one of the parents of ACrypto and that exists as a global object called g_aCrypto which can be used anywhere in the program. | |
Method | Description |
int convertoToAlpha ( UINT uType, char **pcInBlock, int iLength, int iReAllocate = 0x1 ) public |
Converts pcInBlock from binary data of given iLength to a NULL terminated alphanumeric. The method to use is specified by uType which can be either eatNone, eat4Bit or eat6Bit, which denote different encoding methods. iReAllocate will re-map the pointer to a new buffer of the length of the resulting binary data. If using your own buffer which will be large enough to hold the encoded string, set this to 0 and it will not reallocate it. Returns: The strlen of the new alphanumeric string. |
int convertoFromAlpha ( UINT uType, char **pcInBlock, int iLength, int iReAllocate = 0x0 ) public |
Convert pcInBlock from encoded alphanumeric to its original binary form. uType which can be either eatNone, eat4Bit or eat6Bit, which denote different encoding methods. iLength is the length of the ASCII string, it -1 then strlen is used. Setting iReAllocate will re-map the pointer to a new buffer of the length of the resulting binary data. Returns: The unencoded length of the binary user data. |
void convertoSetMap ( const char *pccNewMap = NULL ) public |
This function allows you to set your own lookup map for the eat6Bit encoding routine.
Your map should contain 64 (not more, not less) characters that are alphanumeric and
it should be NULL terminated. Hence your array would be 65 characters in length.
Passing NULL as a map pointer resets to the default map. Returns: Nothing. |
char *convertoEncodeURL ( const char *pccSource, int iSourceLength = -1 ) public |
Performs URL encoding, where all non-alphanumerics are converted to 3 character "%XX" hex equivalents. Returns: A pointer to a new string that contains the encoded sequence. Delete when done. |
char *convertoDecodeURL ( const char *pccSource, int iZeroTest=1 ) public |
Performs URL decoding, where %XX are replaced with then hex value equivalents.
If {iZeroTest} is set then %00 will be ignored since it will translate into a NULL terminator and could
cause premature end of string. Since you know the encoded length and decoded length is less, then
this may not present a problem if this kind of behavior is expected. Returns: A pointer to a new string that contains the decoded sequence. Delete when done. |
int convertoBitCount ( BYTE bTest ) public |
Given a BYTE, this counts the number of bits that are set to 1. Returns: Number of bits set to 1. |
char *convertoBYTEtoHEX ( BYTE byteV, char *pcRet ) public |
Converts a BYTE to a 2 character hex equvalent into pcRet Returns: Pointer to pcRet for convenience. |
BYTE convertoHEXtoBYTE ( char cHi, char cLo ) |
Given 2 hex values 0xHL, it converts to a BYTE. Returns: BYTE result of the conversion. |
char *convertoHEXplusplus ( char *pcRet ) |
Given a 2 character hex value, it increments it by 1. Returns: Pointer to pcRet for convenience. |
char *convertoCOLORREFtoChar ( COLORREF cr, char *pcRet ) public |
Accepts a COLORREF (unsigned long 0x00rrggbb) and converts to "RRGGBB" useful for color manipulation in HTML. Returns: A pointer to pcRet for convenience. |
{type} convertoCRCas{type} ( int iType, const char *pccData, int iDataLength, PCRCMODEL pcmUserModel = NULL ) |
This function generates CRCs for the given pccData of length iDataLength. There are 3 functions where {type}={BYTE, WORD, DWORD}.
There are also 3 iTypes per function, which are: ecrcXOR (XOR bytes), ecrcModuloSum (sums up data), ecrcRNWCRC (polynomial method).
The default polynomial coefficients using ecrcRNWCRC for BYTE is "CRC-8", WORD is "CRC-16", and DWORD is "CRC-32".
You can also pass a PCRCMODEL with your own coefficients. Returns: CRC {type}, depending on function called. |
BYTE convertoMirrorBYTE ( BYTE bX ) public |
Accepts a BYTE and reverses the bit order bit0->bit8, bit1->bit7, etc... Returns: Mirrored BYTE. |
DWORD convertoMirrorLowerDWORDBits ( DWORD dwSource, int iBits ) public |
Accepts a DWORD and mirrors the lower iBits. Used while generating a CRC. Useful during X11 bitmap manipulation. Returns: Resulting DWORD |
class ARandom : public ABase | |
---|---|
This object provides basic Random Number Generation (RNG) routines that are used by ACrypto (encryption) object, as well as providing a superior method to generating random numbers over the RTL's srand() and rand() which are poor RNGs. This object is one of the parents of ACrypto which exists as a globally static object called g_aCrypto that you can use anywhere in you program. | |
Method | Description |
double rngMinimal ( long &lSeed ) public |
Park and Miller "minimal" random number generator. The initial seed must be less than 0 to reset the generator and the same
variable must be used for each call as it updated by the function. Returns: U(0,1) - a uniformly distributed random variable between 0 and 1 exclusive. |
double rngLEcuyer ( long &lSeed ) public |
Long period L'Ecuyer with Bays-Durham shuffle. A must better RNG, but it also takes longer.
Functions like rngMinimal when it comes to seeds. Returns: U(0,1) - a uniformly distributed random variable between 0 and 1 exclusive. |
int rngRandom ( long &lSeed, int iMax, int iMin = 0x0, double (ARandom::*pfRNG)(long &) = NULL ) public |
A wrapper function that accepts a seed (as usual less than 0 first time resets it). You can also specify a
RNG to use (rngMinimal or rngLEcuyer are valid), however it defaults to rngMinimal. Returns: U[iMin, iMax] - a uniformly distributed random variable between iMin and iMax inclusive. |
BYTE *rngGenerateRandomArray ( long &lSeed, int iSize, double (ARandom::*pfRNG)(long &) = NULL ) public |
Allocates and generates a BYTE array of iSize. It contains random values using the provided seed and
optionally a different RNG (default in rngMinimal). Returns: Pointer to a BYTE array of iSize in length. You must delete[] when finished with it. |
void rngShuffleArray ( long &lSeed, BYTE *pbArray, int iSize, double (ARandom::*pfRNG)(long &) = NULL ) public |
Takes a seed, a pointer to an array, the array size and optionally a different RNG (default is rngMinimal) and shuufles it.
Much like shufflihs a deck of cards. Returns: A pointer to pbArray (which has been shuffled) for convenience. |
float rngChiSquareTest ( long &lSeed, int iN, int iRange, double (ARandom::*pfRNG)(long &) = NULL ) public |
Used for testing random number generators. Taken from ("Algorithms in C" by R. Sedgewick; p.517), however I think this should be used as a relative comparison test over many trials and results are not totally useful. Provided to you for convenience and experimentation. |
class ACrypto : virtual public AConverto, virtual public ARandom | |
---|---|
This object's main purpose is to add encryption capability to ARandom and AConverto. It exists globally as g_aCrypto static variable and usable anywhere in your code. | |
Method | Description |
int cryptoSetKey ( const BYTE *pcbNewKey, int iLength ) public |
Access method used for setting the key to be used during encryption or decryption. Returns: Non-zero if successful. |
const BYTE *cryptoGetKey ( int &iLength ) public |
Access method to get the current key being used. iLength is set to the current key length. Returns: A pointer to the const BYTE array that contains the key of length iLength. |
long cryptoSetRandomKey ( int iSize, long lSeed = 0x0L ) public |
Given a size and seed, it generates a random key to be used for encryption and decryption. You have to use the same
negative seed for both to get consistent results. The access method cryptoGetKey can be used to view the key.
Returns: Current seed value to allow you to continue this random series. |
int cryptoEncryptOnly ( UINT uType, char *pcInBlock, int iLength ) public |
Assuming you have set the key, this method will accept an encryption type {ectNone, ectXOR_Blitter, ectXOR_Convolver, ectShiftingConvolver},
a pointer to your data and its length. It will then encrypt your data. Returns: The length of you buffer (this is usable when encoding and encrypting, see cryptoEncrypt method). |
char *cryptoDecryptOnly ( UINT uType, char *pcInBlock, int iLength ) public |
Assuming you have set the key, this method will accept an encryption type {ectNone, ectXOR_Blitter, ectXOR_Convolver, ectShiftingConvolver},
a pointer to your data and its length. It will then decrypt your data. Returns: A pointer to your buffer for convenience. |
int cryptoEncrypt ( UINT uType, char **pcInBlock, int iLength = -1, int iReAllocate = 0x1 ) public |
This is a high level wrapper that first calls an encryption method, then an ecoding method which returns an alphanumeric representation of your data. See cryptoEncryptOnly and convertoToAlpha. uType is an OR (|) of the methods needed for encoding and/or encryption. Reallocation is needed when your buffer is not big enough to contain an encoded string. |
int cryptoDecrypt ( UINT uType, char **pcInBlock, int iLength, int iReAllocate = 0x1 ) public |
This is a high level wrapper that first decodes the alphanumeric you pass it, then decrypts it. uType is an OR (|) of the methods needed for decoding and/or decryption. Reallocation may not be needed since decoded strings tend to be smaller than the encoded one, however this option is available to you if a lot of memory would be freed up in the process. |