中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
4 d" W) J) L3 E9 C5 o( _; C) i% ^' p#include "md5.h"
4 Z7 M+ @1 z9 ~
: g) d4 \( | J+ u: e/* Constants for MD5Transform routine.
*/
0 P- S2 @* Q9 r* a7 D* k
$ x$ n0 P: w1 E# Y
; `0 c% ~& `& I3 O#define S11 7
9 f6 y9 B8 a P7 M) H) q( Y$ P #define S12 12
3 C& t0 n& }1 q: v8 R; f#define S13 17
+ u5 D$ b( V9 o9 [3 N' I$ t#define S14 22
8 q: ~& t7 K6 j/ ]" |& L #define S21 5
8 {- s% H$ c# }) R#define S22 9
( Z- z- A$ D! P! h/ B7 N #define S23 14
4 _( D, h( Y! f #define S24 20
# L* M1 z* G. l! }& L2 F5 N #define S31 4
- _; B U. [$ }( e* S; A% G #define S32 11
3 k$ B! h: y7 | G' i# l* C #define S33 16
8 F& i. \. o. ?9 R#define S34 23
9 s( u' ~7 E0 l9 a l$ A#define S41 6
$ ~# q3 w4 j0 _- Q! ]% J #define S42 10
: O1 B4 a* Z! ] L; G* S- [#define S43 15
8 G# r' {' \& f9 Z: ] #define S44 21
# W; o/ |1 C P8 B' @8 \/ o6 p
' |) Z+ p- c0 q Q5 ]4 v6 `( b static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
% [# y) P* P' C6 [" u) r' @ static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
9 M% o/ T0 w$ U n static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
* c z+ ]$ B. }2 @3 }static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
1 C( X" ~7 z; n' Z3 i4 t static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+ x2 B6 p. G' `. J" q9 m
. C" L3 N& |( f, z- q# vstatic 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
+ p& O3 F- N# o};
" h( s6 [$ G1 t2 H4 b, D
$ e) _# D# v: Q7 _. T5 Y( x/* F, G, H and I are basic MD5 functions.
*/
* v7 x% k$ c, c! i! T #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
) A& M* r) j- `( A2 h #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
1 _6 u" h) t N1 n3 }+ ] #define H(x, y, z) ((x) ^ (y) ^ (z))
% g+ }, J' P/ f# |7 N9 m#define I(x, y, z) ((y) ^ ((x) | (~z)))
- [" K8 R/ y5 T, e/ F
: x2 o! n* u0 C6 Z- ^8 T' d/* ROTATE_LEFT rotates x left n bits.
*/
8 }3 N7 t) W0 ^6 X+ f& O#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
( r, |7 n* R- E% h. K" R- U
4 h% z0 n5 L% q0 | /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. t" O8 e% f0 Z- F$ VRotation is separate from addition to prevent recomputation.
*/
. o N& ~1 n& V' q. ]3 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); \
}
" C# |5 ?$ }9 T#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
# f9 [, S' S! N# 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); \
}
9 R: N& c* [0 {) 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); \
}
6 @# Y" y* \% S7 s* O2 w% Q( q
& v6 ^6 f1 V8 i7 V/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
, B0 G& K: [- m+ J5 D void MD5Init (context)
/ r T/ V, E$ M1 @4 F3 U2 I' A$ | MD5_CTX *context; /* context */
& f' f: ^# {- J1 i Z' u$ g{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
8 h" q0 |! w6 K- B4 `, ]# K' ] */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
1 m% D$ x, E/ E0 `}
7 q, |" W) a; p: E* d
1 `8 O# k4 ~9 c, A8 P9 Q/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
# a1 k0 }& \4 Z void MD5Update (context, input, inputLen)
* h% d, Y4 p; C+ \$ ~2 ^MD5_CTX *context; /* context */
7 _2 a7 f8 ~" e unsigned char *input; /* input block */
* j) o/ G& B8 j7 G unsigned int inputLen; /* length of input block */
9 n+ K! L( H3 p7 x{
unsigned int i, index, partLen;
4 A8 ^. x4 k' v L" j
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
2 ^; ]- W( Q& e# A$ g# q& Y
/* 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++程序


+ \$ ~6 F0 c/ ?) e/ r" f
! M0 a! i3 d% c1 S4 O
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-1 06:27 , Processed in 0.315349 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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