中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
* `+ z8 ~9 a& a5 T' T2 I, I #include "md5.h"
: ]5 I9 y6 a! A8 t1 O: Z8 i' y
0 H: e: q: B w/* Constants for MD5Transform routine.
*/
) Y1 e2 j( d+ ?/ M5 t
9 }* V1 v: T! B
, L/ \9 D, e; w- J7 I#define S11 7
# ~7 m \) K0 M7 w7 a) r I7 E#define S12 12
4 n1 {" {5 o" R: a) g& W #define S13 17
0 _/ ^, H# R: C3 u! Y' l; L2 k #define S14 22
. `* n# |& G8 j, r- k #define S21 5
+ K! b- o# o: f. L #define S22 9
9 P! Z) [. L) V, Z1 O#define S23 14
; _0 i2 e( [, g& w #define S24 20
( {4 P D4 d, K, S #define S31 4
+ f3 S4 B @. j/ c #define S32 11
7 V, @0 b! E2 R, {" c #define S33 16
3 i6 M( J" Z3 a2 R#define S34 23
7 M) F+ x) a& y4 Q9 } #define S41 6
E+ R9 s B6 Q" \! x#define S42 10
H( P* M2 b1 @1 M- l1 s#define S43 15
# L: Z9 m( k3 K7 x' f8 w$ [ #define S44 21
! Y3 j7 E) J3 ~/ V: |2 U
& f* X0 i+ Y0 j static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
4 N) b0 f! l5 ]) c2 i static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
s; R8 y/ Z0 O% {' Sstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
5 [/ d' t7 k5 J, _/ T1 F& N8 zstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" f( T2 ^5 P3 r L+ v static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 H+ D7 v3 i, h1 ]
# Z! ]" b' ^5 n. a* L, Ustatic 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
^+ a2 Y% |& a# U. x };
1 F5 [$ m* B/ b: b$ U% u$ K
/ b S& ~1 y# r/* F, G, H and I are basic MD5 functions.
*/
5 h: p0 i( A3 J* `#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
& q) z2 U5 O, t2 [8 j#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
/ B" C- M% `" \9 l( j #define H(x, y, z) ((x) ^ (y) ^ (z))
+ c/ k3 Z9 X, i, L; h8 N& d) s6 f#define I(x, y, z) ((y) ^ ((x) | (~z)))
2 U; Y5 B# y0 X0 n+ b, n
0 ~. j0 L1 _$ t# I1 K/* ROTATE_LEFT rotates x left n bits.
*/
. N: o$ W) f# V1 c#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
6 G. q7 ]% C# q; w- u, Y
+ z$ D: }$ P: @/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
0 I; L4 h% j* r: d% q( B Rotation is separate from addition to prevent recomputation.
*/
/ E% |* C& X. F0 y6 h G- d#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
5 s% z' q" O! a# I. B #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
" t) B+ q4 s/ N, h# t' ` #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
* r! f. Z( q0 @- A1 h3 R" I: j3 A- u #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
+ n1 k: A4 ?, Y
8 P8 @/ Z J6 u8 @6 u. U/ j/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
' M: Z+ p% C! U& f$ a( O5 e" kvoid MD5Init (context)
5 R# w* W2 |1 f, D7 ^MD5_CTX *context; /* context */
; {8 F) k+ n7 T: A+ v u {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
$ C/ X% v$ y& x */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
% t, ]$ j2 l( w/ l0 Z }
% }6 Q; j6 ~* w# A4 n6 J
* a% c, }2 m `9 |/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
5 L6 ^ I& K) P" |void MD5Update (context, input, inputLen)
- N! ]% n( X3 N! _# x4 wMD5_CTX *context; /* context */
+ E( R N/ C$ d/ f4 U1 w, z9 ~unsigned char *input; /* input block */
/ k) \, C3 J* U7 i* m2 v) A unsigned int inputLen; /* length of input block */
: K# s8 G& K/ d# h0 t. ?( S6 |- w {
unsigned int i, index, partLen;
. c! Z+ q# g) k+ X# D
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
" `7 g" b2 N5 Z$ P! r4 d
/* 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++程序


7 E! P) b# L' F, D4 E
" ^: Z$ d' [% B9 ]7 t( P; n
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-5-19 15:42 , Processed in 0.061641 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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