中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
+ {! U9 K7 K) m4 U8 K7 [#include "md5.h"
+ k& L% Z$ R1 P9 |- @6 {% x2 ^
) P: ^/ p0 _+ w /* Constants for MD5Transform routine.
*/
8 {) c5 u( N. M/ s: b- ]' s6 v
: l1 M; k) X( h- k4 D6 l
% P* w/ U3 b$ @$ O5 p' ]" b: l' X #define S11 7
/ C; |6 c3 r1 b1 ?9 K2 F9 }- I5 r/ @ #define S12 12
& j5 C9 @& U( V9 @$ N% h#define S13 17
$ Y( F/ E* e- V9 u( b2 o' ?#define S14 22
5 m( H J; v) T8 i2 v#define S21 5
# u5 Q/ O# B4 f: B; T6 p #define S22 9
; m1 q+ c0 _% q #define S23 14
/ P$ v/ e2 D2 o% { #define S24 20
# r" ]3 O# k. E0 ?. R" t+ r9 T/ J #define S31 4
# l7 h, P! {3 }: U#define S32 11
$ {3 U0 I+ c, J" d #define S33 16
% J) d6 _( A* N O2 a#define S34 23
+ _1 ]' J* Z& r |/ z: l! X% e #define S41 6
. x' \1 S& ? X% f( g #define S42 10
; q' K! U. X6 K4 V #define S43 15
3 K3 c& o8 N" r+ l7 r#define S44 21
2 d) a+ W/ g, \# c! z/ u
" t2 L ?9 p+ b0 F; e$ K static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
V/ s4 b4 L- j9 L static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
' r% ~3 a; t% |6 N# c* v8 L8 Y static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
! H/ A5 m# D6 Ostatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
- z- y% `7 K* Y8 Estatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
6 i$ Z1 @8 Q3 r2 _4 {
, E0 P& p7 Q3 b" E9 `9 D" mstatic 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
}! [% m; l/ P" R8 U7 n5 i4 \4 }};
0 S- y! n; D O
o! F/ ~, O6 r3 y" j R2 c /* F, G, H and I are basic MD5 functions.
*/
6 U; F+ y) Z6 d P4 U p: H( w8 Q7 |4 d #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
9 s, }, H& x$ {$ e5 _: x7 a, p' } #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
$ H! ^- N9 @- p! H #define H(x, y, z) ((x) ^ (y) ^ (z))
9 [/ Y, D: X; }; P4 G$ V6 h- T#define I(x, y, z) ((y) ^ ((x) | (~z)))
9 S: |" A$ g3 f% R! e
/ p8 i( [3 y: L& J' O* ~5 } /* ROTATE_LEFT rotates x left n bits.
*/
- K( g" N. @$ [8 C N8 O6 [#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
# z4 B7 q( K: A
) i! v( D/ x& H, I/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
3 Q8 M2 V7 R% _" h8 \Rotation is separate from addition to prevent recomputation.
*/
X3 [! r( Y w3 S3 J% | #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
1 Y0 n6 [! g4 |; {* |#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
( L) \8 O5 g# w: \6 f#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
" v5 s, X. E( B, k4 [#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
1 d+ B2 _ g- G9 k, I
/ R1 N3 F5 b+ _) P4 u% z/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
1 {% l/ w6 X: h) O3 ?7 C void MD5Init (context)
& G+ j9 P+ g9 B0 T5 G* ^3 a& B& a MD5_CTX *context; /* context */
/ y$ s5 k c2 _9 u5 R9 s {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
" N* q" V: V. r1 y9 Q */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
( q+ v: @/ K. m7 ~. O3 Q }
2 y; ?8 C! r/ R. m* X/ a
1 a* S% [7 Z, }( q; F% N /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
3 P7 s, _7 u2 n6 r8 H' y8 r' ~2 r) ivoid MD5Update (context, input, inputLen)
1 @9 e F! e- a: o8 l MD5_CTX *context; /* context */
" t/ n9 y' c5 r+ F, I' {unsigned char *input; /* input block */
% b3 e& \$ n' g3 [unsigned int inputLen; /* length of input block */
+ N5 \ x: ~6 a& H {
unsigned int i, index, partLen;
4 C3 k2 D' ]! }9 K- E% k* p
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
" J5 Q, [: A) k, s* Z8 _9 k2 w" R
/* 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 A9 |( e! y* Q
9 C" l$ l! }3 |# A7 Y- P
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-19 03:06 , Processed in 0.073429 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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