中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
! I+ N K1 H! f#include "md5.h"
% V: X H! _- p: p
! V7 `6 @. w! ?" ?4 y/* Constants for MD5Transform routine.
*/
1 A% t# k$ e, r4 O
7 p. V+ J8 Y+ V4 G+ q* ~. z2 ?
! u7 d9 z! t# E#define S11 7
( m4 r# S* u @2 [* b. ]. `1 n3 I y#define S12 12
) {; K6 u* `- G4 b #define S13 17
) n) S. c$ C4 E) S# o4 u#define S14 22
- s0 e3 c1 }' e/ s #define S21 5
8 c7 c8 D4 y4 c& b #define S22 9
. {, R' J, r. T3 x. ?. ?2 M #define S23 14
0 V9 `( e, F: {: y& Q #define S24 20
* _" W7 G* Q% d0 r, Y( V$ S1 P. d #define S31 4
" ?& K* X; z7 [7 p #define S32 11
% R' ~5 E$ g+ @" B A#define S33 16
, e6 w2 q9 U, M/ `4 I: B #define S34 23
$ C; T! N: y- o, y, D' F #define S41 6
) l: ]- y7 `/ o: C #define S42 10
- {& V4 s- B1 l/ T2 @4 O #define S43 15
1 D1 o7 ?) [' ^; ^0 n# H& V. k( A #define S44 21
2 u' r+ t2 T) D# U% S$ n. y; o9 A
! v/ V" |4 F& n' V% u1 e Ostatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 C3 G+ n2 O. m$ Y; t/ Xstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
, C$ p4 H- s1 ^4 L/ e static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
$ W' Z/ [: T' t# [static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
; c9 Z! l4 @5 ~0 e. b" f# r static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
- x6 J( V/ Y6 g
$ b3 N& z' ?: l0 astatic 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
6 n5 s4 ^ i) `6 z0 Y' g; m5 r };
+ C' I6 `5 }. P7 Q
. i/ D% m W8 D( ^/* F, G, H and I are basic MD5 functions.
*/
* V0 D9 r7 F, S& I; @" s- e6 D #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
- Q9 J) \( K( M/ E) N/ } #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
2 X2 Z& q y0 \#define H(x, y, z) ((x) ^ (y) ^ (z))
; K, S# c: u: p' ^ #define I(x, y, z) ((y) ^ ((x) | (~z)))
+ b* o j- r0 ^3 g' U1 \* A# }; g
5 ~: N7 ]' T* K7 H1 {/* ROTATE_LEFT rotates x left n bits.
*/
" E# ?, V; j% ^#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% g" j y7 U4 ` i8 }- `
- A2 h+ m: w* {( B' ^ /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
0 o# s' I" x3 i1 r& Z7 T JRotation is separate from addition to prevent recomputation.
*/
5 m2 t9 r! 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); \
}
K: P( H' o2 } #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% g1 K7 u" P! O0 J! t( {" N#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 u" j* F9 A1 P) o) b' d3 B#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% q9 y& O4 M% t- v" r" B
4 Q, r& B, N* D/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
% {$ d, i5 d7 }8 s7 y6 N+ S void MD5Init (context)
) H3 @1 ^. B+ A+ o- `MD5_CTX *context; /* context */
2 v! N5 k3 j- y+ O Y7 i{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
1 M1 F6 k4 H! M" Q0 z$ a */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
4 S8 y2 I3 G, { }
8 J/ f7 w. z; O: B. W% @" |) a
; c. }3 W/ T+ y' M" s/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
- t, p6 @7 o( N- Z) H! c5 l9 T void MD5Update (context, input, inputLen)
& G4 Y! T; _& k2 y0 aMD5_CTX *context; /* context */
; E) k5 y5 | P: Q% X+ L2 I unsigned char *input; /* input block */
' f- M- @2 X9 ^/ {0 A5 j5 [) K5 b. f unsigned int inputLen; /* length of input block */
& @* B4 Q/ u; h+ z0 S" D{
unsigned int i, index, partLen;
) Q( ~* g9 u% d
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- b+ o5 p% K' f1 v
/* 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++程序


3 R( e2 j! X7 w; ~6 [: k- L1 P: D; C
) {5 r( P C6 ~: S# m
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-8-8 05:53 , Processed in 0.485179 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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