中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
7 t; Z4 {4 [% R#include "md5.h"
, K) Q) f7 p( O5 n3 B
# I* X2 _" w% v+ l7 D/* Constants for MD5Transform routine.
*/
2 [9 r- d. W1 [! r* [" {- i
* h% I/ F, u% q' h5 P& F. T
1 ^2 ^' ~( l8 ~ #define S11 7
. ]% g; ]5 u9 F* N( X/ U#define S12 12
- Z( {; f$ W) ~7 S: A* L #define S13 17
# D8 F" H0 H$ ]- v! j( _ #define S14 22
* P2 j' `3 G# z' \! q) b$ j5 M/ Z; G4 ?0 _#define S21 5
" \+ Y+ u9 }/ \* N #define S22 9
: w+ l; d5 C& |- x) M0 f #define S23 14
% K$ y8 S2 P, { #define S24 20
0 B" `; q# J% B7 z% V2 M#define S31 4
6 J* v) c8 \# r% S) t/ T# x9 U #define S32 11
2 u( _# R" v4 z- X #define S33 16
2 z" W+ p. q- j#define S34 23
G. \! U% c1 a #define S41 6
& x4 ^; w9 I" V$ a #define S42 10
8 _/ [! F! o5 @% }2 b #define S43 15
- J9 c1 t9 N5 v U0 U7 S |2 o #define S44 21
6 n* I0 f9 b* T+ ?% r6 a
5 [: m4 X' W1 X: `6 c5 Tstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
" S" O: O+ G* o8 A static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
0 l' P+ m6 S7 a' ^7 W6 \+ k' S% Qstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
8 U8 ?- L% n; g3 S7 w static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
' {: y- b: [- E9 W. C4 p3 Tstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
~5 Y5 `' Q& i; d3 Y! a+ l o& z* v
6 d. F: @0 |6 Y5 O+ kstatic 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
- ^6 g+ ]3 H! f& ?};
6 Y; _' `* k' T6 ? \: l
& I! n% J* v4 e2 e6 L6 C1 x /* F, G, H and I are basic MD5 functions.
*/
: S4 n% d% R. u1 h# ~8 W#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+ Z* D: G, d( A; ]# p% b N. X #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
; X- I8 P# q5 n; x X#define H(x, y, z) ((x) ^ (y) ^ (z))
# j$ R9 w4 @3 ^8 l. d& ^ #define I(x, y, z) ((y) ^ ((x) | (~z)))
0 M, g. `6 ^) r4 Q3 `* y: m
/ U, ^9 F' H* E: X /* ROTATE_LEFT rotates x left n bits.
*/
0 z$ Z7 M8 p; p" b" F9 A#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
9 l W, ~4 o8 {) G
1 b! L, d! J7 ?' ?/ r# u/ j' p /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 H% J# N6 ^, f( K1 |9 g8 i+ H" M/ J Rotation is separate from addition to prevent recomputation.
*/
9 ^; p& S1 c- I+ x7 R1 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); \
}
9 t2 M5 i; W F0 O #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
" d' R+ z- L2 h5 @9 e$ P. n; g, P#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
1 D- [# ^9 ?- Q+ p1 U #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
7 d5 V7 k4 W' {* F, G6 l
; G, M5 w. M4 ^9 Z' a8 q. f/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
n- e+ X, e; J: f* g void MD5Init (context)
, f3 T: [& i! d8 S q MD5_CTX *context; /* context */
' t$ b! D2 b( O. T/ g$ _* ?{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
' k1 s7 [# }" V' u2 y5 K& I5 P* Q*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
, W+ ^- b: T4 n8 j4 D }
" h8 n4 |% s/ Z, R! T5 n, f
3 y5 ^. d! u5 S, q /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
0 B2 m0 A3 u, \+ q' D+ C void MD5Update (context, input, inputLen)
# K p9 n: q0 W& [0 Y8 u MD5_CTX *context; /* context */
" e7 j6 }; I" K/ _; kunsigned char *input; /* input block */
7 U* x, P0 p. P! @4 X% H unsigned int inputLen; /* length of input block */
- _7 j7 u" B# C7 ~. V' @ {
unsigned int i, index, partLen;
9 [; p# Q6 b! m/ y
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
' i8 m8 P# A5 ?/ V( }
/* 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++程序


- w. E- T9 d. V$ ], j a4 I3 `, Y
) U( G! X) t/ L) B7 k0 N/ B
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-7-2 18:59 , Processed in 0.149547 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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