中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
3 `5 F; } g7 L2 L" B#include "md5.h"
9 Z! w9 C4 a5 A1 c2 G
X; e: |6 o5 H /* Constants for MD5Transform routine.
*/
# x5 a* @! V5 q9 R/ h: A& a
- N; O/ x1 m7 c7 t
/ I" k# p, [5 z$ W. i1 w" S. |#define S11 7
, M: L3 y1 G" S/ H' \3 i#define S12 12
6 @: u+ f# Z! g+ f( o#define S13 17
7 y) T3 M6 F( n3 a. w1 r, x#define S14 22
/ S* K" }$ m. r+ d$ ?#define S21 5
% c7 s6 K+ Y0 F5 V( _9 D8 x" l/ S#define S22 9
' g" p+ X" X6 u, W#define S23 14
6 M, }) m( H# F0 v4 `! D5 |; y#define S24 20
/ ~: y; t& o# D9 Y* H/ T2 |7 [! ? #define S31 4
% e: J: D# w' D7 D8 a" D( z) E- J#define S32 11
: z# X7 n/ A* k7 C#define S33 16
9 ^4 ]; T0 }. A4 y#define S34 23
. T: c6 ~2 Q# r& m/ R _#define S41 6
. X+ d3 ]& V, V#define S42 10
, O5 w! [1 j7 q0 @0 J #define S43 15
) ~2 v$ e5 f" H; p9 v; W; z#define S44 21
! @4 v+ C1 V& a0 T9 z: m2 b
! ]) T- R! f7 S+ {9 x' f& Z/ Cstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
/ _' L2 D: T7 [ R$ V9 m static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
2 Z( g" a/ l1 e1 G8 l5 C9 astatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
" z& {" E9 R \5 l j2 Sstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
* N' T8 C! C3 X/ R: a static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
: r! U5 s' {& ~5 t% g7 g4 I
X6 ]+ F* S3 z( [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
' G% A& b/ Z' N% p};
, @, M( e' N/ N
' G+ K L4 z3 z+ k+ X2 E: K( R6 s/* F, G, H and I are basic MD5 functions.
*/
1 Q+ |, m0 E: G O #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
& d/ V3 j" R& z& \2 r' a; i#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
" ?$ d8 B) n' h! {2 t7 w4 j #define H(x, y, z) ((x) ^ (y) ^ (z))
& r3 B% r9 w' o' }2 _" N% X- |: q #define I(x, y, z) ((y) ^ ((x) | (~z)))
# y# W, ]5 E+ Y& b6 X* Q% y+ K
@4 J6 ]: t8 |, c4 P8 j- E B /* ROTATE_LEFT rotates x left n bits.
*/
1 @9 Q' r. [- f0 H #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. H) Y9 k0 w1 k2 x! y2 _
' V2 N9 W$ y$ |! O! y( B% ] /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
% {) b0 b1 @) d Rotation is separate from addition to prevent recomputation.
*/
' \" R9 C! @1 F, U% }3 L3 k #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
) `8 N8 u: `2 F! F#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
: T4 i) N% U! l- o- Y9 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); \
}
* o8 T) D5 U( t1 j( r#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
$ Z8 A R) w, Q; C! T
& I$ q2 Y: q) b* O1 Z8 ^+ j& L/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
1 g6 O- X: X, J& i* d; fvoid MD5Init (context)
1 ^% ^) l7 v9 c) E2 \0 OMD5_CTX *context; /* context */
- j$ |+ m a6 y{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
, U) a9 B% _2 h: N */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
% z- N# }6 x; o' i( l) d, M8 w% e}
* \4 v. U7 P2 U
* U5 W) n' h! J6 h /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
* x$ @! J z5 ]8 Nvoid MD5Update (context, input, inputLen)
+ f- x" _4 G! ~% `$ ^$ G" w- d MD5_CTX *context; /* context */
# p) T2 s" _ l1 f: iunsigned char *input; /* input block */
7 }" Q: e" s0 K+ p3 t unsigned int inputLen; /* length of input block */
( i# X& w) V4 p' T/ c: j8 Y+ } {
unsigned int i, index, partLen;
1 E$ P: o8 I' N7 c9 C D
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
$ W) V M: V5 O+ n5 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++程序


: e( S2 ^" W; j: J& w2 b: v# A
8 d4 Q, Y! Z( X9 K( {0 [# U7 p
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-9 20:21 , Processed in 0.156882 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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