中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
* D! N" e! z; q0 H #include "md5.h"
0 y5 R! k% o# I; t, l. \5 N
0 B- s7 z9 t9 f5 I* s/* Constants for MD5Transform routine.
*/
/ A( _8 d* Q% k3 e8 y
1 v7 @- w6 r# i) b6 D8 p9 y8 e9 Q
3 v0 d1 ]) t8 R+ \+ s#define S11 7
& ~/ L6 b) Y, O9 {/ Z#define S12 12
) N1 y: V3 J m! f* k- {9 |0 O8 T #define S13 17
9 _1 O% |" O' v9 x' e7 ]- A #define S14 22
$ O9 a/ ^6 }. N0 [% o# h5 _9 s #define S21 5
3 K8 W6 S8 t/ L: l5 g! V #define S22 9
. [- l# B2 a2 ]/ d$ T #define S23 14
' S8 w& h! f( k1 E. Q `#define S24 20
( Y. b$ |, {( c. R J#define S31 4
3 K9 o+ ^$ W! _; a, t* n( _#define S32 11
3 H. S" }7 _) k/ G( U #define S33 16
/ I8 w! N% w, ~0 a. o #define S34 23
- j* T: e! T5 J; i- J% @#define S41 6
" p) D8 R K5 J, `" t" _ #define S42 10
; h. r$ `8 H- F8 }+ K* O#define S43 15
: @. C4 u! c$ o+ c* Q& d5 B& Q; A #define S44 21
& j& F% c% \- s: S
: \( c( x9 H. B: Kstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
" K7 ]( a! I7 U8 d# ^, u; Cstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
# \4 _- f6 M8 ?, d" M: w4 g/ Sstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
; X9 e9 u" C% istatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 }' |7 ^' ]2 P5 m! d0 O8 j static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
* p" e/ a# u$ D. {
0 Y* T% y2 W9 }" U6 A/ ? static 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
$ |8 }) ^2 q8 y. h };
+ r5 q K; k5 |+ w+ e9 n
* ~- ~9 E& T' g z2 B6 Q/* F, G, H and I are basic MD5 functions.
*/
: H" {% @. {: b4 } #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! U0 J5 I- t& d ` #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
$ x0 t% }/ P4 m#define H(x, y, z) ((x) ^ (y) ^ (z))
# G+ e9 A. y$ O( f#define I(x, y, z) ((y) ^ ((x) | (~z)))
# w9 ^7 z5 I, U( s8 H
3 a) R6 o0 ]( p# P: E/ E; A/* ROTATE_LEFT rotates x left n bits.
*/
9 w' ^- L" t; f5 F- v7 k#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
; v! U2 Y/ b' L% m* J1 p/ y
2 o0 f# |7 t, }, j6 b9 O /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
1 D `: M+ h" K G Rotation is separate from addition to prevent recomputation.
*/
+ u5 J0 E! b1 d0 {% S#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
! X6 c& i$ p5 M#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
/ }- _7 T" q+ I8 C- e#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
F/ ^2 v" f4 T, } #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
( g, @, T) z( ], m" Z$ m
/ z& z7 _9 p. n0 k0 j$ i" ~' i/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
/ W' {5 U/ ^1 l3 e void MD5Init (context)
* ^& j1 W% Z$ e! W& ^. Q; [+ kMD5_CTX *context; /* context */
: U& A! [3 e# O {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
; T( l7 d9 J& I* k# m0 a4 O6 U*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
]/ r' ^( ?' }5 J" ?( R5 U6 `! L1 Q }
* E% O2 N! h" \" l- X. I
5 l' h: _7 w2 N5 S) U" u' M/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
/ J R2 J4 v' D void MD5Update (context, input, inputLen)
" D' l2 f$ X# T$ i% e) [9 a# c2 MMD5_CTX *context; /* context */
( b) I0 o' i2 M S, S6 c/ Y8 V4 _ unsigned char *input; /* input block */
3 v; T' n, @6 u) y* T% L, b unsigned int inputLen; /* length of input block */
6 R6 ?2 K3 C- } {
unsigned int i, index, partLen;
( g9 \1 e7 S1 Y M2 u3 O" g
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
" H5 |9 a' K3 A F 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++程序


& K" V( g" y% ^" F
& T4 q7 q% H, `+ M
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-9-11 05:06 , Processed in 0.055155 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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