中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
& {+ w. @$ |. h0 G5 C! J" N4 J#include "md5.h"
& H7 |1 m9 g$ ^% B" ?
! E) r& M* M3 `/* Constants for MD5Transform routine.
*/
4 V& Q& ]! C6 U z. g
' r2 X9 L$ N& w8 ^9 l6 `
- ]5 }% e6 U! O. u1 E#define S11 7
4 h/ F/ W n \( j, \7 h a- D) j #define S12 12
0 _3 U1 L1 y. I$ A( W#define S13 17
5 f4 \2 k) [+ `/ O u#define S14 22
1 A2 P7 a9 d5 q8 e# d#define S21 5
. p p4 V9 d: B0 D #define S22 9
1 w" c* d: }7 o& I1 H: h0 [$ q #define S23 14
: E2 c% f8 f+ [# o #define S24 20
4 F6 f( Y) j$ i) X #define S31 4
0 Q8 F/ ?8 c8 s #define S32 11
2 e6 h2 g9 c7 J3 P2 G. z #define S33 16
+ Q8 H! @' O2 P #define S34 23
6 O, N3 ~( \& c2 f: S* E #define S41 6
9 Z+ H( }) g5 j5 m#define S42 10
% F1 ]3 G' E! `0 ]#define S43 15
6 }" f" l' g( x1 I: p2 s* s#define S44 21
. {1 G" K c" J S/ T2 l
0 q Q V1 t% e' J& T' F static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
& c2 m$ S" z! L/ q+ b static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
) X5 u! \% Y1 g7 r) D/ x Zstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
) a# v+ m( s9 m# y1 i, P static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" o$ s% O/ X+ y) e7 W static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
. f- B; C6 |% I) |% V9 l
* |7 F' ]! o6 V$ `/ g' V" Fstatic 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
- X2 `' f8 d% S9 V* v };
" A8 ~/ C9 h9 j: G- r+ I
& d0 D& @9 a4 ]) n+ A9 r/* F, G, H and I are basic MD5 functions.
*/
) O$ @* m, {% `4 O9 ~0 g- P; `& j#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
3 F, p6 q! V$ o# v& ^#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
0 Q# h ^4 M' K #define H(x, y, z) ((x) ^ (y) ^ (z))
o6 D; H' X8 M#define I(x, y, z) ((y) ^ ((x) | (~z)))
' a. {4 M& ?, n9 y9 w
8 z* P! H' n, Q+ {3 D /* ROTATE_LEFT rotates x left n bits.
*/
* l! d$ H- m9 M$ H2 T #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- j3 M' Q4 x1 H8 l( v
2 Y! _: K0 P# {: z9 U7 D% N/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
3 W% e4 Q& }8 D; U: U2 `) y4 |Rotation is separate from addition to prevent recomputation.
*/
$ X7 v4 P7 c! ^& A% k @- g#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
: H* n6 T- y1 n' I+ R1 [ #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 {+ S, G! Q# F' o) r#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
L3 ]4 a& e+ m/ P #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
: U y3 s" t4 f( N( e/ L5 ^2 L1 u- x
2 h$ R) Q& d) G7 `# W3 }, s/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
, A1 c6 D. V/ M3 J# S void MD5Init (context)
! n9 N: B z! C( s! q: B6 WMD5_CTX *context; /* context */
. ^1 r r# o; x" g{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
' K$ \: f% f! \! W2 Q7 w1 h) ^0 o */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
. L z: A: T; c' i}
- |0 ~# s9 ^5 H1 r
. E' K9 q6 X( ] /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
* i+ l# |& j% Z8 I. [ void MD5Update (context, input, inputLen)
/ F/ I3 Y! q# W( X4 q6 \0 b MD5_CTX *context; /* context */
- k- U/ d0 P) P! Z% T: ]: O# U/ kunsigned char *input; /* input block */
$ q4 p4 R& ^5 p" ?unsigned int inputLen; /* length of input block */
. ~4 f, j! Z; m$ |{
unsigned int i, index, partLen;
1 {& q- K& X4 h- p, `0 w% H
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! _2 l* c ?: ~: n; w9 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++程序


7 X5 r0 D1 G. t" ^! x
: n# o6 ~9 V/ z2 j* K- a+ L2 ]
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-19 06:20 , Processed in 0.064281 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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