中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
% b, x: k/ b" A1 R #include "md5.h"
V1 A7 O+ F6 Y6 m$ F1 Z# z4 W
& V' w' ~3 ^( s/ ? /* Constants for MD5Transform routine.
*/
% f/ |- J+ r/ g! Q& R( A% F
- E5 T$ I/ y& |+ V9 ]) n9 V4 B
; Z. D+ K9 v1 ~#define S11 7
; P+ N9 }4 ^2 X' ~8 T P& j1 z/ m#define S12 12
% c# M9 L8 `2 y) _" y- S#define S13 17
8 A F: O; ?3 v! C8 \, n$ J4 C3 G! S#define S14 22
/ J" l) \3 o: F! H #define S21 5
& V! ?: H" r7 V- _' J #define S22 9
/ B0 K* c8 c c3 l; e" r#define S23 14
% M8 y/ h- D* r. ^ #define S24 20
+ f! @7 e/ w2 t0 N Q: b #define S31 4
& Z' P( w Q7 |! Z; @1 o( y" a& J#define S32 11
7 @/ [$ m" s5 I: ]9 a; i, Z: A' y#define S33 16
* Q- R: s; [5 b #define S34 23
5 R% q8 P) e- u2 D#define S41 6
4 v6 M" }- W+ {7 s#define S42 10
1 ~. b% X' A2 r+ m+ v3 s" _, ^#define S43 15
( q/ n* O) F* a4 l #define S44 21
: _# |" X# |: i( d% [. N
+ a7 E; g \; I# {; l6 Z3 K' J/ Bstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
. ~! o+ {( V8 z2 e. A static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
( b) @( r/ ~" z; o static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
# b' U" t! d" Q/ M5 _; t9 Ostatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
4 u' m2 ]& d8 |: u6 e7 b: u$ s static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
5 S" |, p- G' z9 g' B8 b6 y
3 \- L0 \" U7 |2 C1 r! T 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
3 E2 m" E6 D$ R};
7 u4 t U5 r5 e0 B' i
) R! F2 z9 R4 B: y/* F, G, H and I are basic MD5 functions.
*/
4 D8 x& H, u" h) u #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
# Q/ @9 b5 p& P% p8 ~+ T #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
) |5 O( a; {5 m, N #define H(x, y, z) ((x) ^ (y) ^ (z))
6 S$ o2 y' v6 i #define I(x, y, z) ((y) ^ ((x) | (~z)))
. `' A. G# |) f/ b
( F" T1 H' r/ r /* ROTATE_LEFT rotates x left n bits.
*/
& E% H6 v6 ^! u7 n#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
0 u+ |2 X, J, a9 q/ l
. w% M& W9 [8 m) x; C /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! H& Q d- V7 |* m5 [9 v1 o" j# GRotation is separate from addition to prevent recomputation.
*/
0 \2 E1 b/ l/ I: } #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 z. G" C( v5 f$ W; @( I5 ^3 |5 V#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
" x- R8 i0 o, `% j; }! `) o #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
~7 c3 j$ @: x0 d' l- r% ]#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
0 b* f7 w$ l8 s1 C; O( G
) ` b7 C3 {% T, \. l/ X /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
. | [" M) V+ F3 u" H H+ Q. Ovoid MD5Init (context)
& H5 h* E. Z$ H; w! O V" N- o$ j, XMD5_CTX *context; /* context */
6 l3 b' I R8 o& a {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@* [# G( i& t, w% @; v */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
+ c" K% A- ^0 v" n" G}
0 q3 l6 k2 m$ y- q& g
& R$ M+ c% q# ^6 @, g& `$ w/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
9 C% ~; G/ g7 J9 E/ }+ v4 r/ K void MD5Update (context, input, inputLen)
: R( p$ k4 t# W$ mMD5_CTX *context; /* context */
" c% S( u9 e) V) f; q1 [) m. runsigned char *input; /* input block */
6 t7 z$ g2 M$ b j. d5 Y6 sunsigned int inputLen; /* length of input block */
2 l& s' ^. G8 C% {1 d; B {
unsigned int i, index, partLen;
/ ~( T# w4 U% r* Q0 q
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! K# Y- J$ G- N2 a
/* 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++程序


' J1 K. r7 O5 Z. B m
! {. D- _ `2 {; R
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-8-3 00:52 , Processed in 0.097419 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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