乐乐天 发表于 2004-11-26 20:11:20

md5加密算法C++程序

#include "global.h"<br>
#include "md5.h"<br>
<br>
/* Constants for MD5Transform routine.<br>*/<br>
<br>
<br>
#define S11 7<br>
#define S12 12<br>
#define S13 17<br>
#define S14 22<br>
#define S21 5<br>
#define S22 9<br>
#define S23 14<br>
#define S24 20<br>
#define S31 4<br>
#define S32 11<br>
#define S33 16<br>
#define S34 23<br>
#define S41 6<br>
#define S42 10<br>
#define S43 15<br>
#define S44 21<br>
<br>
static void MD5Transform PROTO_LIST ((UINT4 , unsigned char ));<br>
static void Encode PROTO_LIST<br>((unsigned char *, UINT4 *, unsigned int));<br>
static void Decode PROTO_LIST<br>((UINT4 *, unsigned char *, unsigned int));<br>
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));<br>
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));<br>
<br>
static unsigned char PADDING = {<br>0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,<br>0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,<br>0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0<br>
};<br>
<br>
/* F, G, H and I are basic MD5 functions.<br>*/<br>
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))<br>
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))<br>
#define H(x, y, z) ((x) ^ (y) ^ (z))<br>
#define I(x, y, z) ((y) ^ ((x) | (~z)))<br>
<br>
/* ROTATE_LEFT rotates x left n bits.<br>*/<br>
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))<br>
<br>
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.<br>
Rotation is separate from addition to prevent recomputation.<br>*/<br>
#define FF(a, b, c, d, x, s, ac) { \<br>(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \<br>(a) = ROTATE_LEFT ((a), (s)); \<br>(a) += (b); \<br>}<br>
#define GG(a, b, c, d, x, s, ac) { \<br>(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \<br>(a) = ROTATE_LEFT ((a), (s)); \<br>(a) += (b); \<br>}<br>
#define HH(a, b, c, d, x, s, ac) { \<br>(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \<br>(a) = ROTATE_LEFT ((a), (s)); \<br>(a) += (b); \<br>}<br>
#define II(a, b, c, d, x, s, ac) { \<br>(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \<br>(a) = ROTATE_LEFT ((a), (s)); \<br>(a) += (b); \<br>}<br>
<br>
/* MD5 initialization. Begins an MD5 operation, writing a new context.<br>*/<br>
void MD5Init (context)<br>
MD5_CTX *context; /* context */<br>
{<br>context->count = context->count = 0;<br>/* Load magic initialization constants.<br>
*/<br>context->state = 0x67452301;<br>context->state = 0xefcdab89;<br>context->state = 0x98badcfe;<br>context->state = 0x10325476;<br>
}<br>
<br>
/* MD5 block update operation. Continues an MD5 message-digest<br>operation, processing another message block, and updating the<br>context.<br>*/<br>
void MD5Update (context, input, inputLen)<br>
MD5_CTX *context; /* context */<br>
unsigned char *input; /* input block */<br>
unsigned int inputLen; /* length of input block */<br>
{<br>unsigned int i, index, partLen;<br>
<br>/* Compute number of bytes mod 64 */<br>index = (unsigned int)((context->count >> 3) & 0x3F);<br>
<br>/* Update number of bits */<br>if ((context->count += ((UINT4)inputLen << 3))<br>&

guoyun786 发表于 2004-11-26 20:22:48

md5加密算法C++程序

<br>
<br>
页: [1]
查看完整版本: md5加密算法C++程序