中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
8 ^7 ?0 b8 M$ C* [( g #include "md5.h"
$ u% f2 G" c' X
. k1 R- Y7 Z4 d7 z& S8 \! C& N: Z/ p7 B /* Constants for MD5Transform routine.
*/
% H/ s1 f0 @. [- }$ c+ d4 S+ N+ }
p0 ?: f- T0 u% o5 n B
; x8 \* g) Q c #define S11 7
' L$ @4 M$ j! }, f#define S12 12
h( L5 u5 r9 {6 ~#define S13 17
& S1 t6 x- J3 |% M9 U ]/ h #define S14 22
/ t3 S! t/ e( e9 b$ d; } #define S21 5
: C8 r' c/ v8 g) ^#define S22 9
# p- _ H8 s( t4 S3 V#define S23 14
# `7 K$ N" |# H9 N2 E* A+ m #define S24 20
& \; b1 p6 w! u. c, P- @! s( P `! ~* H #define S31 4
$ L1 B, A4 A- d, i# W% k #define S32 11
( u5 S) @" V6 Q& }& E; Z) V/ V #define S33 16
2 I2 X( T# k8 l #define S34 23
Q+ m- ]" w9 w% k#define S41 6
3 t; R* e/ Z/ h #define S42 10
, N3 o- r) Q9 L6 ~' o#define S43 15
/ m" I- R7 l' S7 S: M' m3 P# N #define S44 21
0 ]% w9 ?# C- o) P+ _- D( D9 k
( m2 v/ _5 A* T1 Bstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
5 c0 } j- \8 f! G static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
3 O6 e- { P4 A- ` static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
8 f: ~& g& a* l# N5 P1 Cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 r9 y \5 G6 ^4 x: ] Kstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
# U6 r, w: x: L& i4 \+ h0 J. A& F/ x5 r
" \; n$ {( M/ e) vstatic 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
4 S: E8 t, ?$ S};
# c, c9 W$ l1 I: z
. s& V& V. L0 e: S ^/* F, G, H and I are basic MD5 functions.
*/
& T9 F4 t' F% g5 {( H3 J% i #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
( g5 E' w6 G: O #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+ ?$ Q/ U, R" |8 c; z* D #define H(x, y, z) ((x) ^ (y) ^ (z))
6 w8 F; x. X" h' Z! d #define I(x, y, z) ((y) ^ ((x) | (~z)))
7 m5 U8 k0 t3 R+ p5 M/ v
! Q' O* J" M! B! v% q/* ROTATE_LEFT rotates x left n bits.
*/
! Q. }# R( r' i+ ~( { #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
( U/ q6 c7 J. f6 w
; h6 ~: [3 r6 r- T+ {6 x; d/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ N- @7 {; K3 ^$ QRotation is separate from addition to prevent recomputation.
*/
0 U, V) J5 X3 M+ v0 } #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
5 v `/ L. C3 r #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
- a$ u& [/ U% l0 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); \
}
0 w+ p. P# V$ O" o: d#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
$ h5 g$ v) t/ S6 v9 K" k
% t$ ^. l( ~6 K/ P: ?. }; E/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
3 r! t* O5 f' N8 L) S& i: x void MD5Init (context)
9 M( |! h& S0 b: A+ t7 C9 a MD5_CTX *context; /* context */
% t. V; l3 R' B- D, I {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
! G2 ^9 t: w* Q+ `! p*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
: `5 }6 Z+ N% a% E( n }
- l! O% K( R2 U% Y" l5 S
3 a1 C" t. b$ ?: A b /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
9 e$ F2 z9 v% Q' l9 h! a) _" \ void MD5Update (context, input, inputLen)
: A u. E8 C. o5 T1 n MD5_CTX *context; /* context */
$ p, p) I( ^' O' U" d9 Funsigned char *input; /* input block */
6 J3 _4 p* `9 A$ |/ ~8 I; n unsigned int inputLen; /* length of input block */
8 L v$ X( W2 k( ` {
unsigned int i, index, partLen;
6 V0 ? G y# Y
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
5 F" y% X. U6 _3 [2 v, t- x
/* 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++程序


4 f( Y/ Q* l; p
, n1 D- E. u7 f. p- S# x5 u
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-1 05:37 , Processed in 0.322485 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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