• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

CheckSum.cpp

Go to the documentation of this file.
00001 
00006 #include "CheckSum.h"
00007 
00008 /****************************************************************************
00009 *        CheckSum::add
00010 * Inputs:
00011 *   unsigned int d: word to add
00012 * Result: void
00013 * 
00014 * Effect: 
00015 *   Adds the bytes of the unsigned int to the CheckSum
00016 ****************************************************************************/
00017 
00018 void CheckSum::Add ( unsigned int value )
00019 {
00020         union
00021         {
00022                 unsigned int value;
00023                 unsigned char bytes[ 4 ];
00024         }
00025 
00026         data;
00027         data.value = value;
00028 
00029         for ( unsigned int i = 0; i < sizeof( data.bytes ); i++ )
00030                 Add ( data.bytes[ i ] )
00031 
00032                 ;
00033 } // CheckSum::add(unsigned int)
00034 
00035 /****************************************************************************
00036 *       CheckSum::add
00037 * Inputs:
00038 *   unsigned short value:
00039 * Result: void
00040 * 
00041 * Effect: 
00042 *   Adds the bytes of the unsigned short value to the CheckSum
00043 ****************************************************************************/
00044 
00045 void CheckSum::Add ( unsigned short value )
00046 {
00047         union
00048         {
00049                 unsigned short value;
00050                 unsigned char bytes[ 2 ];
00051         }
00052 
00053         data;
00054         data.value = value;
00055 
00056         for ( unsigned int i = 0; i < sizeof( data.bytes ); i++ )
00057                 Add ( data.bytes[ i ] )
00058 
00059                 ;
00060 } // CheckSum::add(unsigned short)
00061 
00062 /****************************************************************************
00063 *       CheckSum::add
00064 * Inputs:
00065 *   unsigned char value:
00066 * Result: void
00067 * 
00068 * Effect: 
00069 *   Adds the byte to the CheckSum
00070 ****************************************************************************/
00071 
00072 void CheckSum::Add ( unsigned char value )
00073 {
00074         unsigned char cipher = (unsigned char)( value ^ ( r >> 8 ) );
00075         r = ( cipher + r ) * c1 + c2;
00076         sum += cipher;
00077 } // CheckSum::add(unsigned char)
00078 
00079 
00080 /****************************************************************************
00081 *       CheckSum::add
00082 * Inputs:
00083 *   LPunsigned char b: pointer to byte array
00084 *   unsigned int length: count
00085 * Result: void
00086 * 
00087 * Effect: 
00088 *   Adds the bytes to the CheckSum
00089 ****************************************************************************/
00090 
00091 void CheckSum::Add ( unsigned char *b, unsigned int length )
00092 {
00093         for ( unsigned int i = 0; i < length; i++ )
00094                 Add ( b[ i ] )
00095 
00096                 ;
00097 } // CheckSum::add(LPunsigned char, unsigned int)

Generated on Thu Sep 30 2010 01:27:21 for RakNet by  doxygen 1.7.1