📄 cwmd5.h
字号:
#ifndef CWMD5_H
#define CWMD5_H
//#include "wintype.h"
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
class MD5
{
public:
MD5(void);
~MD5(void);
void Make(const PUCHAR inBuf , ULONG inLen , PUCHAR outBuf);
void _init(); //Length = 16
void _Update (const PUCHAR input , ULONG inputLen);
void _Final (PUCHAR digest);
//检验校验结果
bool Check(const PUCHAR input , ULONG inLen , const PUCHAR check)
{
int i;
UCHAR summary[16];
_init();
_Update(input , inLen);
_Final(summary);
for(i = 0 ; i < 16 ; i ++)
{
if(summary[i] != check[i])
return FALSE;
}
return TRUE;
}
private:
ULONG state[4]; // state (ABCD)
ULONG count[2]; // number of bits, modulo 2^64 (lsb first) */
UCHAR buffer[64]; // input buffer
void _Transform(const PUCHAR buf); //Length = 16
void Encode (PUCHAR output,const PULONG input, ULONG len)
{
ULONG i, j;
len &= 0xFFFFFFFC; // len = len / 4 * 4;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (UCHAR)(input[i] & 0xff);
output[j+1] = (UCHAR)((input[i] >> 8) & 0xff);
output[j+2] = (UCHAR)((input[i] >> 16) & 0xff);
output[j+3] = (UCHAR)((input[i] >> 24) & 0xff);
}
}
void Decode (PULONG output,const PUCHAR input, ULONG len)
{
ULONG i, j;
len &= 0xFFFFFFFC; //len = len / 4 * 4;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((ULONG)input[j]) | (((ULONG)input[j+1]) << 8) |
(((ULONG)input[j+2]) << 16) | (((ULONG)input[j+3]) << 24);
}
};
// F, G, H and I are basic MD5 functions.
#define ROUND1(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define ROUND2(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define ROUND3(x, y, z) ((x) ^ (y) ^ (z))
#define ROUND4(x, y, z) ((y) ^ ((x) | (~z)))
// ROTATE_LEFT rotates x left n bits.
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent recomputation.
#define FF(a, b, c, d, x, s, ac) { (a) += ROUND1 ((b), (c), (d)) + (x) + (ULONG)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define GG(a, b, c, d, x, s, ac) { (a) += ROUND2 ((b), (c), (d)) + (x) + (ULONG)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define HH(a, b, c, d, x, s, ac) { (a) += ROUND3 ((b), (c), (d)) + (x) + (ULONG)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define II(a, b, c, d, x, s, ac) { (a) += ROUND4 ((b), (c), (d)) + (x) + (ULONG)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -