中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
3 w' ~8 T" ]$ D" b#include "md5.h"
m) g( [2 N5 g5 Q: I
: Y8 G6 D3 C# k |2 i. S /* Constants for MD5Transform routine.
*/
* D: d6 P, a( _- l; X4 A' M
; Y: p4 w$ a. B8 V' Z
( y8 a8 _! M! ^# J `9 e0 h0 S, `#define S11 7
; g" N) B8 x* h% j #define S12 12
7 A5 ^$ t8 E2 y& ] #define S13 17
& Z8 i# _2 U+ G7 V; R#define S14 22
( L: i) j3 ?3 H3 k8 H& K #define S21 5
8 p2 O, f/ m6 a& `. N; s3 t/ T#define S22 9
. ?/ _8 y `% |( k( [#define S23 14
* [8 L% Z, { t- O #define S24 20
, G9 M N: b* ^% A. t3 }#define S31 4
5 ?8 t. k4 L! ~8 @2 Y* I #define S32 11
( P1 {5 \ u+ |' u R7 g* x- _& P' | #define S33 16
! L/ }3 S9 n+ o! h4 U ~0 ? #define S34 23
2 V7 P$ v& T8 j- z' @6 H8 r: F #define S41 6
, f; i5 c5 m, K8 |9 t#define S42 10
* _2 ^' \: e' b1 O; {8 P #define S43 15
2 G1 K3 @( j& @& c2 O$ Y+ Q#define S44 21
+ O; G0 d# d% R0 `
9 S$ w3 Z' l: ]" V: U* R+ v" ~ static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
: h0 q/ M2 ]* D static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
) u# ~6 M' C. m1 E: d+ ?8 I& |9 a7 U static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
+ c* S" g3 }- v2 i" ~; c: k static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
v7 [& j! f9 r3 Xstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
! a( C& a0 H1 Q' H! K
, X9 K* q [# Y1 P8 y: Q 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
# U9 i7 W5 d% _};
* q. u0 `: t: F; j/ D1 A* U; P
' I# [& j8 v- z) z& K /* F, G, H and I are basic MD5 functions.
*/
. ?/ X- y$ J9 i3 w#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
- P% i2 g& \3 B+ i6 C' ^ #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( V3 W1 c0 H6 A* P( O5 X2 g1 U#define H(x, y, z) ((x) ^ (y) ^ (z))
/ Z1 s8 y% D# }: x+ q3 X; y #define I(x, y, z) ((y) ^ ((x) | (~z)))
: C, \+ k2 v [- g2 w7 [2 t
0 }: g! {( f" n8 U /* ROTATE_LEFT rotates x left n bits.
*/
, Z, R: T9 g7 R #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
! Z. k8 n2 T0 G7 {4 A# x! A5 A
4 d' ^5 A; u4 z /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! x/ n8 p& T( _- }) d( NRotation is separate from addition to prevent recomputation.
*/
1 P" X3 t! Y2 ]7 z' _ #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
/ D& M- m+ ~# F: Z9 b5 M#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
1 R4 c2 v) K) T( j" J( t#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 b/ R. c- D8 K/ ` #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
* T1 T! h2 c8 A6 H0 N3 [
" ?- E" t6 w" O" A* |, d6 }# P/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
+ j, f' Q* j* G. x; n; W; n void MD5Init (context)
; O/ r5 y9 S% h' [+ } MD5_CTX *context; /* context */
4 Q$ }" x# F0 m2 B0 i% x- V{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
: ?: V) \4 E k7 N*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
, f: {9 X5 a+ F5 P; g}
0 r; c/ C& a, W# x8 D0 k V
+ S, t: t+ Q6 S9 }4 N N, [/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
! }9 X7 F( t9 U. F; L/ x! N2 ^: @void MD5Update (context, input, inputLen)
4 l& x( ?* o q& WMD5_CTX *context; /* context */
5 {# |: x7 {! t4 K& g0 J unsigned char *input; /* input block */
! m6 t E( G' t, bunsigned int inputLen; /* length of input block */
$ s, s; t3 j- O6 w2 A- @ {
unsigned int i, index, partLen;
1 v, S t8 [$ I5 E. l
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- O( E1 e9 T- |8 a3 n- C8 J* Q# {6 R6 I
/* 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++程序


$ z$ M- S" H ?; Q* u9 h
$ y* W0 i, O& x* W+ R. c& F
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-19 14:09 , Processed in 0.087980 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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