中国安防论坛

 找回密码
 注册
查看: 5867|回复: 1

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
6 ]! I9 w0 C: C- z& j #include "md5.h"
. {2 ]6 J" ]- I: k1 @
" W7 z& J7 E4 w/* Constants for MD5Transform routine.
*/
: C- e/ r8 b8 }5 @- D' [
6 M/ i: t1 ?+ F0 g0 E
g" {) R4 r3 f( s8 R/ [ #define S11 7
4 B2 e% P1 C. [) r+ {3 _#define S12 12
3 @- j9 [7 h2 T #define S13 17
; v( z0 S* B% w% q; Q6 M3 u% P) p #define S14 22
$ r& B( t N; Q" j#define S21 5
K8 H( |8 Q5 f#define S22 9
X! E9 u8 F% Q% p/ L% b/ Z#define S23 14
2 ~8 H0 p* y) ` #define S24 20
. e" j r' A/ b; ~( `# L#define S31 4
1 @ b/ t% S5 H2 K2 { #define S32 11
6 x8 l. l- i/ v* P( [ #define S33 16
4 E. R# q# Q& M, i #define S34 23
' q/ v1 b& p6 T* X ~: t0 H3 B#define S41 6
) E1 C5 `* T5 `* z: @ #define S42 10
& \4 l3 n2 S9 Q7 V2 w, e' D#define S43 15
5 [6 w+ d2 \4 y* i#define S44 21
% S# y1 D, D) ?8 B$ A
4 n8 e0 b" v5 p! a# z static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
3 a: F4 k' L3 P. a5 Mstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
* o& M5 c' w8 Q* m3 F8 Q$ p static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
& c+ }5 _8 P/ E' Z8 fstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 l& `" R1 f) v: u- i+ A; p; Sstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+ K/ y# Y; c- T9 F( J; G5 T$ K
3 T& ~9 U3 L! i; istatic unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
. V6 ?; S; _3 v, y, X+ T& k };
0 p3 w9 i: v2 y& [: H
" c( T6 M' @ \4 L$ \ /* F, G, H and I are basic MD5 functions.
*/
+ W) t9 V. V8 U# o#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+ d+ [0 D0 x V" N! f' [& E7 ` #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( u! h7 L/ g8 v$ q #define H(x, y, z) ((x) ^ (y) ^ (z))
- o, @1 n& r( K: F' k #define I(x, y, z) ((y) ^ ((x) | (~z)))
" m+ G, f" ~, u( W) Z2 x
$ T9 R0 v' p% ?+ _ \2 [ /* ROTATE_LEFT rotates x left n bits.
*/
; I! W) @! ^. q, c) B #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- c% w/ g7 @: Q$ U: q2 X
& o/ E F4 g9 o# f( W" | /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
5 A9 G% `% @) y% k/ v ]' Y- ~ Rotation is separate from addition to prevent recomputation.
*/
: U1 b* V' n- ?, a#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
S" I" W9 a: L, Q5 ]+ q9 X- L #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
c3 G& Y3 }$ q W0 j#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
4 ^3 ^7 @) _( @* \7 I3 h6 u" Z; Q- j #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
6 Z4 j( }6 _$ C- G) F9 S
3 F/ J" Y. `8 e- ~/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
/ p* L( K+ Q% ]* y; fvoid MD5Init (context)
- a, y$ W- Q: E2 X MD5_CTX *context; /* context */
0 k9 a, L( O! u9 X8 b+ G, w8 e {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
8 I0 w6 Z: H: u1 ~. C ^6 s */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
4 U C" V. M" _0 H( c* M }
+ W2 X U7 D" i. k7 S$ ~
" n+ ]6 k: y: J' `: n9 J3 m& X) c /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
4 Y; y% l6 |' G% yvoid MD5Update (context, input, inputLen)
( Y& [& k* u2 C4 u( Q MD5_CTX *context; /* context */
, B, B: W$ {* P. S4 i3 e9 ^) Bunsigned char *input; /* input block */
2 V' O2 M+ Y2 }/ W' f unsigned int inputLen; /* length of input block */
9 I' X; W* l1 h3 v) X% y) R {
unsigned int i, index, partLen;
6 l: [! Z- U3 _: o* M+ c! E
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
6 R2 C) h( F7 x% x+ N9 b
/* Update number of bits */
if ((context->count[0] += ((UINT4)inputLen << 3))
&
不在競爭中變坏,就在沉默中變態

安防知名大师

探花

Rank: 7Rank: 7Rank: 7

积分
1057
QQ
发表于 2004-11-26 20:22:48 | 显示全部楼层

md5加密算法C++程序


8 Q0 ]! ?. s* i. |5 I* L* d# O
+ E; C. z% X Q1 Q) X7 Z
guoyun786@sohu.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

安豆网|Archiver|手机版|中国安防论坛 ( 粤ICP备09063021号 )

GMT+8, 2026-8-26 17:43 , Processed in 0.080515 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表