中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
6 H1 @4 ~5 \2 c: J #include "md5.h"
, a. e+ l C3 b0 k Q$ B2 t5 m
+ b. F' `. ]+ w2 C" s8 ?/* Constants for MD5Transform routine.
*/
5 \. m3 D7 o4 L
" k7 p/ ]6 C _6 o
/ H& t6 a" S3 B" f" S#define S11 7
0 T3 H& `* I, L+ k% G( C! k4 U2 h; Z#define S12 12
4 w9 ]% z. \6 c: y z#define S13 17
$ E* a8 Y$ b7 Z. m/ J #define S14 22
' S: R- `# A# s #define S21 5
6 o# y& v% K! `0 v% `- h+ e/ g #define S22 9
6 ]1 @4 I1 \( D- S7 S/ C#define S23 14
1 a- G1 H4 r7 _5 [" ?# l; ^- Y#define S24 20
0 I4 j! s/ {( s8 T0 x6 \#define S31 4
" k, c! J; n& [& j4 K #define S32 11
+ A: D0 _2 f8 J, G/ X } #define S33 16
4 c0 Q/ b/ Y( X% V" s" i0 X #define S34 23
- _" t* z( b" P' R% B #define S41 6
' N8 I7 I+ A* ` W6 S #define S42 10
. G8 H# x9 e R#define S43 15
7 f+ B% V( [/ X6 c #define S44 21
# ^0 ~, M5 V$ K( U6 q
! N9 n0 U. @1 _4 gstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, {- m" [: g" O% Qstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
, a& o0 b- F7 E5 T' L1 Lstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
9 W8 g2 g) S3 R2 J @/ X static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& {% w- `5 |6 ]! n; Q; |static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
U% n9 S' C' b
/ \; s" F1 \8 d, e1 F8 O$ ?% @ 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
+ b% Y% q6 |4 } Z6 c% ]8 y};
2 |' S7 h( [' K. B" U. B
% \( t1 {' U% {' r) @7 n% M /* F, G, H and I are basic MD5 functions.
*/
' T, T5 ~9 j7 W% U |. E#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
, R- o" H( O4 g; w2 A. Z1 C #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
6 H( _' P& d, V) f8 t, a #define H(x, y, z) ((x) ^ (y) ^ (z))
7 T8 N& j; D7 i+ n( X#define I(x, y, z) ((y) ^ ((x) | (~z)))
: }/ |7 Q! r& W$ R6 c Z% E
" _ T. ^- q( }6 g' R8 a! O /* ROTATE_LEFT rotates x left n bits.
*/
1 X9 z. h8 J a( K; z6 t#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
9 p9 X) E/ ^) O' [( h
8 c# w# \9 a( J Y2 G3 K/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
4 m% M2 I) ]: u z8 A" P. K Rotation is separate from addition to prevent recomputation.
*/
% r$ o- s- J. p5 O( C# } #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
+ X$ ]7 d$ [/ Q" G/ g#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
1 H3 z. ^. B. ~+ ?9 x: ]7 A#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
# j' \1 s* s- H! F #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
- s$ [9 U+ ]7 d4 @6 J
# @$ g: |; ^2 X1 L /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
e+ F2 s6 o3 z6 ` void MD5Init (context)
. p7 ~/ f4 j% } MD5_CTX *context; /* context */
& J; D; T, k; [+ e: l1 g* k$ V% m{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
$ Q2 K" j' a8 {% h% z */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
" {. Q! A5 I, y9 v+ J2 G }
+ q7 y& V* X/ m
; A H" i: X8 m- l' L# {7 E$ t! z9 p /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
# L( V+ _: V4 @9 ` void MD5Update (context, input, inputLen)
( V& t# r& H$ y1 Z! j* W. l MD5_CTX *context; /* context */
/ i& N- r# j& ]; Bunsigned char *input; /* input block */
. F( h$ L# P' Y# f9 j& J5 e( Q" ^unsigned int inputLen; /* length of input block */
& X: h& O; q4 x8 h' R$ O{
unsigned int i, index, partLen;
( n {; V% T5 E" U2 H/ J
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
0 s( b. d: J G4 D) [; F: q
/* 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++程序


! m( @4 w3 |3 _4 m7 @
( ^3 a# b- v+ I2 ~2 h4 j
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-30 06:05 , Processed in 0.131199 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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