中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
) Z' s; \! ?& j( A5 | #include "md5.h"
( y0 c6 P% w0 D/ q$ m
% s0 J" L/ F$ G a1 o4 ~/* Constants for MD5Transform routine.
*/
$ B2 C) ^$ D6 v5 y, C
. w% J* l* ? s$ |0 n9 N
3 t3 ]& s6 k# J- x" e, v#define S11 7
8 ^; H) a6 q1 \# r #define S12 12
5 C6 R8 b$ u+ |$ e; T#define S13 17
8 x# t- s- y( R+ v& o#define S14 22
0 ^8 x) R1 _6 N8 N6 ~& L#define S21 5
6 m8 L1 i: @6 P- S' s( F: y#define S22 9
8 g1 [9 C, I, N, J, d$ | #define S23 14
/ u3 I' u" @; w) Q #define S24 20
9 f& b' A2 ]) f! l! { #define S31 4
& }$ f2 Q/ C* R4 g0 V6 { #define S32 11
) [% ^1 i" h0 w/ y" O0 J #define S33 16
6 Y1 }" o8 d7 m' ?& _4 N% T7 d- A#define S34 23
3 C! s' n5 u4 a5 z' A. c#define S41 6
1 S: }$ i! V$ G$ E4 K #define S42 10
# p8 D2 ^. Y& ^ #define S43 15
Q1 O5 J, p" q# \% b9 H #define S44 21
2 v) l: z/ f/ m
8 W; I& m- d& ]1 k4 ]% _2 M* Hstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
) L4 f: K0 R0 \, {# i static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
4 R5 v. E6 I9 U. I/ Vstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
/ q r" r' q6 k' u; J6 X5 F: astatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
6 }* Y: p! C* ?3 M7 N0 ^3 o. F static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
, V* z6 E. O& z) [# ~: Y
. j) L8 K% @# J2 q W! Ostatic 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
- d. V/ L6 L8 y! P0 [0 U: H };
& o8 C4 |+ Y4 {/ |
% @$ o! W1 o4 s# f8 G7 O3 e /* F, G, H and I are basic MD5 functions.
*/
# ]! {( D2 A/ e+ q' S#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
, t9 p3 k$ \6 ]2 ~, }" v: @#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( G% J+ |8 w0 M" k' @7 s( p #define H(x, y, z) ((x) ^ (y) ^ (z))
2 v s; ?. l/ h1 c #define I(x, y, z) ((y) ^ ((x) | (~z)))
2 p6 a+ P7 C/ Q- @( \# S
0 d) i3 @1 w7 F" q: f- h! o/* ROTATE_LEFT rotates x left n bits.
*/
" a: k) u9 v6 }" o #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
& q, z$ D& N4 [" L
' {' n5 v4 p( L. M+ V$ q- [/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ A+ J7 Q- U* iRotation is separate from addition to prevent recomputation.
*/
) h& M2 X, J! {/ 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); \
}
+ E6 }( B: M5 E! q0 N #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
2 \2 D+ Z: y9 Y( C7 Y& B#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
d( E% M7 B1 |. r+ a+ K7 D6 ~3 V: z#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 T+ X8 `' r) P8 t8 w
8 [( s/ h9 @( {8 J/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
5 ?* i. L5 X0 l9 jvoid MD5Init (context)
( ]* V g4 ?: u2 V/ P MD5_CTX *context; /* context */
8 ], V" `; H' k{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
- [0 X3 |- ^, O6 i' @*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
! O1 p; _7 _0 W1 Q+ ^/ V+ I }
" \( u" P# S, h/ ]) ^9 E
, P2 i& O$ K9 G6 v" V) A5 s1 R/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
. p) H a- O6 y4 t( T void MD5Update (context, input, inputLen)
5 y& n% D4 W T MD5_CTX *context; /* context */
2 i: i* _; f; R8 s+ H' v1 [ unsigned char *input; /* input block */
; j9 d# G' t% \8 K% i }! Bunsigned int inputLen; /* length of input block */
% q0 f! n1 W7 K0 o! D" P! y {
unsigned int i, index, partLen;
* J5 J7 M1 c1 b; M& r o" ^
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
( s3 C4 P. L( f z
/* 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++程序


2 V* y& x: v1 V
8 B: e# ?' K6 _7 m# g
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-5-20 11:17 , Processed in 0.067573 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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