中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
- |! R- P9 P4 W( T: A$ s: ?0 k #include "md5.h"
, E1 Y% L5 U, J* X" }5 W
( `3 Y7 o4 P8 T2 R /* Constants for MD5Transform routine.
*/
6 k' d6 ]: f; m" ~- c) A
( C! Z, ?7 o8 ?) x
; q& [8 e4 s) g: k#define S11 7
( Z7 @0 V0 S, G/ w# [+ T7 J" \& ]2 J#define S12 12
8 E# y$ l: k0 m5 c- r& \#define S13 17
, k% ?: }& L# Q/ ? #define S14 22
+ J! `: y5 M/ C5 }( M' w$ O #define S21 5
1 {2 W+ C, G0 z6 R9 [#define S22 9
8 t+ ]3 H& g7 L- j #define S23 14
# }: R3 N0 n! Y, z* w$ B #define S24 20
7 [; e6 c9 b$ o #define S31 4
! x& Y: a3 |( `) [7 R9 a #define S32 11
$ |8 b' H8 {- {#define S33 16
+ K( b) x- \: Q- T7 |& `3 t #define S34 23
* y0 j$ i- T$ e ]#define S41 6
! x7 H* V f R# W#define S42 10
4 v4 N1 j" a. w; V, Q#define S43 15
' O8 D$ J, q$ J2 w) V' {; Z#define S44 21
( O" d2 D0 L( h U- V% J
- l- |; T" K5 q9 a! K! kstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
9 n; ^3 c* {/ L. Y; [7 xstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
& k* r7 v8 t8 K! p- P6 w$ w1 { static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
4 Y6 a7 G7 D. `/ j, b H static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 a* }; j+ D2 g static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
: w% P1 W* [# E
% \5 x- c4 `% C 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
7 T- C4 F# w) z @0 ]% } };
/ i2 {$ U# I: B2 u# n
$ }$ _' g. l9 _+ Y/ C3 L3 r" j: O /* F, G, H and I are basic MD5 functions.
*/
: |8 M( c4 x+ z4 i+ ~! X #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
- ~% p! f/ E) G7 ~ #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
`5 a. q, h5 S) [5 {7 D. x #define H(x, y, z) ((x) ^ (y) ^ (z))
& C" m3 L2 S2 @; v4 ?* b #define I(x, y, z) ((y) ^ ((x) | (~z)))
7 J7 Q# w7 [1 {7 C# n9 p: S5 J: V
5 m- a1 Q2 O2 c5 v% M1 j/* ROTATE_LEFT rotates x left n bits.
*/
$ j+ u0 c1 [0 S8 f( p% Z. Z/ f2 E #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
# a) i. a% q- z% ]
; Q2 U+ ^2 D; M; d& a/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 e( N- e& | n+ r, R Rotation is separate from addition to prevent recomputation.
*/
, b8 H/ H4 D; g! G! e- G |#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
/ d2 S! S* ?4 S #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
3 {$ b+ c+ U) Q #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
/ |+ e* U. b, J/ G8 P" h' ?3 h#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% A& N8 O! M7 q1 Y; g5 D9 s
! e( m! I w9 r8 |" d B; ^ /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
8 z( N4 I2 J& ]+ ~4 evoid MD5Init (context)
" n8 Z7 E, z5 Q! W. O8 n, S& { MD5_CTX *context; /* context */
, \5 k2 B3 b. Y {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
- q$ P) Q) K! A */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
! [: g2 I. `" c- @7 Y8 Q3 w, Z}
5 k/ f- }3 h( R+ l; r! _: S- [
" s# B, O& m8 Y' ]4 ?8 C/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
9 t( y1 Q. ^; l' O+ t6 ~void MD5Update (context, input, inputLen)
! t( Y0 d& @- r6 o' X MD5_CTX *context; /* context */
2 b7 y# f: [! R3 S8 a& B4 d! y9 Qunsigned char *input; /* input block */
4 ]( k% g( q+ C, ]# I6 U9 f1 y unsigned int inputLen; /* length of input block */
& K4 C* X1 {# z f {
unsigned int i, index, partLen;
' O& X2 J f' M' [5 w
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
, a' e6 f% j$ g3 \5 h3 J# B% r
/* 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++程序


" J9 r! n& j5 H/ ?7 M+ c ^) u5 J
" l9 p; R7 {) p& d1 {
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-12 13:45 , Processed in 0.061056 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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