中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
3 B! F# Z& Q4 P2 q# {#include "md5.h"
& ]5 e, ~8 x$ Q; ^7 }6 j- _
9 Z# @3 D8 q. B1 F) N6 T/* Constants for MD5Transform routine.
*/
% ]( f: h* z3 h( x" Y9 i
& ~9 |# D8 A3 a; `7 X& v
* ?& H ~3 P8 N6 ^9 f7 }' s. U( M#define S11 7
) \9 q1 i2 G* h/ Z/ s& h9 C #define S12 12
1 B ~" F3 ?6 c* |* y#define S13 17
6 E- n0 d- h5 h8 a' A#define S14 22
7 s, n' l/ H" \$ c #define S21 5
/ E1 Y) G9 M; w* K X- t#define S22 9
' H( a1 j/ h+ `#define S23 14
6 U& M9 |" P$ @5 N- f#define S24 20
( y# T5 @/ h& v#define S31 4
3 Z1 C2 |; `2 y) O, k5 ~4 r3 y#define S32 11
* x' Q! G, O, @" c8 i #define S33 16
3 |* _2 e0 N+ O" B#define S34 23
9 H: V8 F# {$ N d#define S41 6
3 y# D2 Y' Z+ c% y9 O s#define S42 10
( C! F5 k9 B7 I8 K/ |5 T- N' E8 V #define S43 15
: y, v. a" E) v+ _9 X #define S44 21
" K M% h; I/ U* R$ k: b; O& F
) T+ a6 g. h$ u; h4 J$ t- }: Z! q static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
. E; s7 W! M0 F' J" l- k static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
u6 V+ c- `" F6 E+ Hstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
% J4 q f6 s1 w3 Cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
. L/ I6 f- T! i8 c8 Z, Ustatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
V6 s# Y, U8 p! e' ^- q
( l% r; g) g# l1 V1 T: }' W8 [ 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
' y- ]- b5 j l/ v5 d; r };
7 p4 G; y7 ~4 G; P2 l" q
+ G& b( D6 a* m [% {! o5 T$ e" e/* F, G, H and I are basic MD5 functions.
*/
2 S ^0 g; D9 g) C/ ~2 [6 c#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
) `8 R$ F# U+ o3 {0 e1 E4 U #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 ?% u6 c& K9 T( u! V6 j l #define H(x, y, z) ((x) ^ (y) ^ (z))
4 L7 L5 w5 h% N5 e0 A #define I(x, y, z) ((y) ^ ((x) | (~z)))
; l, T7 t7 a/ u, ?% r. m% q0 n
( |+ c/ H1 o+ {/* ROTATE_LEFT rotates x left n bits.
*/
% T# d; i! H! l; [ #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
. o0 i9 C( Q( ^$ l2 o5 t
& I( P6 C( m# Y* J/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
' |# ^' o; Z+ Y7 x! }) n3 t# M: v Rotation is separate from addition to prevent recomputation.
*/
9 D9 ~! m/ @; ~# W! a6 ]3 M #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
' I1 t% ?" A/ k. z/ U" I#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
7 n$ Q2 t3 J5 w4 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); \
}
/ O, W" ]8 U& N. l6 r7 s #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
) ?* R0 q) L( g! B
0 h, u ]" S, f: i% a/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
, Z, U! X" P' ~. p# B) t3 k7 u. Cvoid MD5Init (context)
! z5 {+ h3 l7 u4 Y+ U# m MD5_CTX *context; /* context */
9 N; o( `4 M3 _" M/ \' |{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
* P& K+ e: o) p& t4 b, F */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
" j& W# v0 g9 f7 \, j }
8 _" Y* r% Q+ u! H0 e7 g4 J
- n& Y- |4 `% H. M5 U* c/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
- a7 z2 {6 z7 K+ z7 r" d9 L: D void MD5Update (context, input, inputLen)
1 n9 ?5 }( i! j6 l: o/ L( W MD5_CTX *context; /* context */
7 O* ^7 |7 t% \+ ^0 Vunsigned char *input; /* input block */
- \; u" I; P$ W- ~/ ^ unsigned int inputLen; /* length of input block */
$ I6 ?, [$ v* U. s{
unsigned int i, index, partLen;
+ ? w* X$ G) f1 @( o# Q
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
G, u/ x8 _8 C' m% M
/* 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++程序


$ I" p; _. I" c ?0 x7 F4 m
" O7 n. F, ^0 @4 R) Q5 T% q6 b' P* m
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-5-17 03:05 , Processed in 0.098941 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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