forked from excitom/vp-spades
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksum.cpp
89 lines (78 loc) · 2.43 KB
/
checksum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "stdafx.h"
#include "Checksum.h"
/****************************************************************************
* checksum::add
* Inputs:
* DWORD d: word to add
* Result: void
*
* Effect:
* Adds the bytes of the DWORD to the checksum
****************************************************************************/
void checksum::add(DWORD value)
{
union { DWORD value; BYTE bytes[4]; } data;
data.value = value;
for(UINT i = 0; i < sizeof(data.bytes); i++)
add(data.bytes[i]);
} // checksum::add(DWORD)
/****************************************************************************
* checksum::add
* Inputs:
* WORD value:
* Result: void
*
* Effect:
* Adds the bytes of the WORD value to the checksum
****************************************************************************/
void checksum::add(WORD value)
{
union { DWORD value; BYTE bytes[2]; } data;
data.value = value;
for(UINT i = 0; i < sizeof(data.bytes); i++)
add(data.bytes[i]);
} // checksum::add(WORD)
/****************************************************************************
* checksum::add
* Inputs:
* BYTE value:
* Result: void
*
* Effect:
* Adds the byte to the checksum
****************************************************************************/
void checksum::add(BYTE value)
{
BYTE cipher = (value ^ (r >> 8));
r = (cipher + r) * c1 + c2;
sum += cipher;
} // checksum::add(BYTE)
/****************************************************************************
* checksum::add
* Inputs:
* const CString & s: String to add
* Result: void
*
* Effect:
* Adds each character of the string to the checksum
****************************************************************************/
void checksum::add(const CString & s)
{
for(int i = 0; i < s.GetLength(); i++)
add((BYTE)s.GetAt(i));
} // checksum::add(CString)
/****************************************************************************
* checksum::add
* Inputs:
* LPBYTE b: pointer to byte array
* UINT length: count
* Result: void
*
* Effect:
* Adds the bytes to the checksum
****************************************************************************/
void checksum::add(LPBYTE b, UINT length)
{
for(UINT i = 0; i < length; i++)
add(b[i]);
} // checksum::add(LPBYTE, UINT)