中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
+ ?3 c9 P' t8 @ #include "md5.h"
# o% F6 H( A, L2 r5 L" L
/ z: z e1 X% L /* Constants for MD5Transform routine.
*/
* S, q, F) a1 E. `
- u; T2 k1 E& [
9 q: q& b6 [$ ~' L #define S11 7
* T2 H* y4 {7 L" _ U, Z$ @' f! Z#define S12 12
4 W x/ P. L8 }7 P8 \ c #define S13 17
5 W3 \/ j8 h4 H" g #define S14 22
: C* v7 o1 d. q- x/ y' X: x( I5 O6 B#define S21 5
2 Y7 T# z+ J' c* ~4 F9 ^#define S22 9
! M7 D8 I! W( F4 S3 ^ #define S23 14
4 {: T& R5 C3 g& p! Q: W #define S24 20
; O/ N$ l: q3 P#define S31 4
5 n. s6 e$ s! I/ D#define S32 11
8 d% Q- l2 f1 z5 C3 a#define S33 16
0 {9 _6 ~9 x& M9 P1 v% g#define S34 23
# n# P* j5 O3 Q* M #define S41 6
% U: `7 _" n/ N+ N #define S42 10
$ Z* W5 g# L/ N B& m- ?6 s#define S43 15
# \0 D' C( ]6 b, t. D/ o #define S44 21
f* I) x1 B/ o) _# [' ]
7 o/ o) v/ U) Q$ H; h8 W8 x static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
+ k6 y2 b% A- P' P; _ static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
& D1 c d: u2 q# M1 h( @ static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
+ b" T5 t% O! q& Dstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
9 {& ^8 p9 u u; F* {/ V static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 ?7 V8 _2 y; p0 x4 \
0 t, j8 o% r; K9 I% C, r/ sstatic 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
; p. G3 x6 b: {; [, |+ z };
0 ~, L$ f+ r7 K+ v! Z' n
. ]; T; I6 q1 } /* F, G, H and I are basic MD5 functions.
*/
7 X2 O. A P" K #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
" d" r& w# P+ E+ b7 V4 n#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
: o3 L z- C: _7 N& S% H; Y#define H(x, y, z) ((x) ^ (y) ^ (z))
! |" ^- `+ \" N0 C' P #define I(x, y, z) ((y) ^ ((x) | (~z)))
- i0 ~ `3 }6 f* n
- O5 _1 Q5 k/ a6 F" `/* ROTATE_LEFT rotates x left n bits.
*/
$ T& T, @" x2 U3 h3 h, v #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+ J2 o5 l' J2 m3 V+ b) l8 J
- Y) R3 f* l* v8 r3 k/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! q1 C6 m0 z2 e+ O/ Q: f+ e7 W Rotation is separate from addition to prevent recomputation.
*/
' w6 P* Q" Z+ E0 r' G0 p# [+ ] #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 u6 i! `! q2 h. w& Z#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
8 Y- b4 ~; t. x( F r5 T8 E5 u#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
$ i6 @1 e1 W! h+ j2 u#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, Y3 h z3 `; k5 S' j
. c5 e1 G9 f7 F; R' v( E% q% {, W/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
' K% M3 f( X5 v( \; M void MD5Init (context)
- S8 c1 u, r0 j. @3 V MD5_CTX *context; /* context */
1 e& b" E1 m. C/ o( o: a# G{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
6 I' L% t' M% W2 T/ h */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
+ i5 G z: d1 I+ ^ }
1 f# |/ |" C) i# O+ o% \ _
2 Q# ?* @' a b4 h- }6 t/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
, Q% Z! E, Y$ ^7 g* P6 F' I M void MD5Update (context, input, inputLen)
+ F+ s; K( b7 \0 [4 _+ C* VMD5_CTX *context; /* context */
4 ~* k% j% d$ f( Q% ?unsigned char *input; /* input block */
- ~$ d' y8 i, K2 P9 S unsigned int inputLen; /* length of input block */
! [1 |* J r. @, a2 E! V! Y* W' I {
unsigned int i, index, partLen;
: q. ]/ E9 a) ~- m, i
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
& V0 I& P2 }4 B: z# ^+ c
/* 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 q# z7 i5 _; X; b) D
2 E" z' q. ]5 O, U
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-9-1 21:57 , Processed in 0.082340 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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