中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
$ e$ z: |) o# F# S" l& D #include "md5.h"
" V, r' M2 e z3 ~
4 `0 V6 ~; h% U /* Constants for MD5Transform routine.
*/
% [" R8 F8 F! R8 w; A1 ]$ h8 J
1 e/ @8 F. N9 u' p m% _ c
# ]. N3 Q, \9 F' Z8 m3 e#define S11 7
- h4 B: Z! h, a ~#define S12 12
2 x: b3 c5 A* B7 u6 f#define S13 17
6 X$ T, |7 H- J+ Q/ t#define S14 22
* P: m% p1 S2 k; r! b0 m #define S21 5
. T& w/ ^( }& ]2 l1 m) N4 @1 }0 n#define S22 9
7 F0 @3 V5 v0 [5 m% k#define S23 14
$ @) L9 _% u& B* T3 X- F #define S24 20
% N! J, ^6 [, \5 q! @( k #define S31 4
; U5 k" {# _( x$ |5 p0 ` #define S32 11
; b; {) [" l+ a& S#define S33 16
4 W7 {( d& D. k7 M7 d0 R#define S34 23
7 u) C! C% o3 Q! ^) I$ Z #define S41 6
* K/ h0 i9 V2 x; D #define S42 10
% W; @8 N; X8 [+ Y; f, D#define S43 15
8 y8 `& J: J, s' n- d #define S44 21
( M; j! B" O, W4 [% F
0 K* [! B: c" s p1 O% ~. `' rstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
& x' l) \1 R# R" X% ^. @; @ static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
: F9 n U6 x! @5 l/ ^' _( S# S, bstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
0 L, s( n4 x3 l2 ^1 r( i. q static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
; H7 h7 s! d$ `" V1 y$ M static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ g" o5 l$ T3 c8 _. f
$ Y4 i( X3 W6 b7 Z& Lstatic 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
/ T: \* c7 k6 Q/ t; m( a% z};
6 i% a4 y+ R$ N5 N6 L& b
+ b$ c3 \& |+ [* y* |4 O. K/* F, G, H and I are basic MD5 functions.
*/
7 O7 z, y- X1 u7 P) E, u #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
4 i g$ O# L+ l8 Z! v #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% `" E$ {0 |& O7 `2 M+ f+ P5 W/ V #define H(x, y, z) ((x) ^ (y) ^ (z))
! ~+ \" j* r" J6 ] #define I(x, y, z) ((y) ^ ((x) | (~z)))
Z3 j7 x" s( ~' `) ^) u& x
; m( U0 ]& ^. R/* ROTATE_LEFT rotates x left n bits.
*/
" E% r1 l& n t #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
0 e7 D9 M% \8 r# ^5 y4 h
$ A; ?4 a' X1 }* M8 h& D# W$ A/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
. ]& L1 i, u$ X# b0 ERotation is separate from addition to prevent recomputation.
*/
( `( Y* \8 p+ a; b& u' f' P #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
) G# R# o; {1 B# M; k$ U) ~#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
6 f! Z4 r6 {" m! u& J- _" A# S#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
6 q+ b- B" L& m+ v# o#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
( X7 i) t' ]* ?% F3 b' c
! c/ O; q8 L0 u1 E /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
8 @( l, ~( [) _' \5 j: @: \ void MD5Init (context)
; M7 \- @5 p6 sMD5_CTX *context; /* context */
) v2 e% D+ K9 H; \& B f& ?5 \{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
5 C! e' ]; a* H( F! Q */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
* }/ v2 |( d5 d( D}
% M6 P. W4 ?- K: d! K- F$ e
3 z+ H' L& ?& @ /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
Q5 G) b6 z! }+ K9 ivoid MD5Update (context, input, inputLen)
) D. [/ I/ j2 SMD5_CTX *context; /* context */
8 C7 }1 c. K& ?7 ?) g& | unsigned char *input; /* input block */
& @! `' H# L' K: G! {* g unsigned int inputLen; /* length of input block */
, K; C8 E, Y+ a' |& k{
unsigned int i, index, partLen;
1 f( O @5 F% y: A- }: h
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
0 H+ D- o+ p M6 y$ Y5 @! O/ x1 M O
/* 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++程序


9 R8 Y% i& s" X( {; g% L* m8 q
; {% k: }7 P+ h; K& f& k' g
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-7-22 14:08 , Processed in 0.122225 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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