中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
4 |$ Y4 E, J0 }' }6 I& J) ]+ z #include "md5.h"
! R! P! D; r6 k
/ I, K, V: g6 }6 p2 O/* Constants for MD5Transform routine.
*/
* N# X& [6 \* G2 g6 v' B
: P* J, q! G& b; T7 r3 d
( C7 M+ }8 C8 y- l r0 i #define S11 7
/ y J: s( I" J6 P$ ?8 L* x3 v+ F$ ~#define S12 12
6 Y6 A( ?" K4 K# }" d #define S13 17
+ M. D \8 X& A #define S14 22
4 s* {6 E1 @$ ~7 X* F$ X4 J+ o: L& Q#define S21 5
! h4 q, l }& |' h9 T; k6 f #define S22 9
3 p* S( Q. t1 q #define S23 14
t' Q/ }! H0 S. q7 a, e#define S24 20
' ^# D- x9 g" P$ I' k #define S31 4
, Q6 c. B/ {) u, |5 J$ J P( u #define S32 11
; J( s6 t- `$ _( y#define S33 16
) E( G) n; ?: @ R. J #define S34 23
/ S! u5 o0 P& e& s: h( ]) d: C9 n#define S41 6
* T- H7 a% a/ |" P# L#define S42 10
1 I/ M; p, u7 ~) _#define S43 15
" j' L$ j6 N6 C5 b; \7 g' C#define S44 21
' `# G% ?2 q- \, q' P
7 K: ]0 q: i$ e" I$ ` A# j static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 k" w9 p: r5 {# \9 ?' O static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
3 T7 W0 S" ^* s: A; j9 @static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
( _$ I% z( n! u# p2 S/ T& Cstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
- R ^5 n: R. m static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
4 o; Y/ c* J) d4 D) z7 d6 T- F
# q; I, A. s- ?1 a( i4 d2 Nstatic 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
! L8 c) b0 H% \$ x, E; l; Y };
! v: }- j$ I7 K
' l" Z: h1 S) I/* F, G, H and I are basic MD5 functions.
*/
+ ?" x# D; R" g; o" b0 O8 c#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
& V; T/ y3 g: L2 Z: O8 C: ] #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
8 q6 z+ I6 [6 d9 l& Z4 \ Y #define H(x, y, z) ((x) ^ (y) ^ (z))
0 g$ P2 E1 ]$ c2 k5 b #define I(x, y, z) ((y) ^ ((x) | (~z)))
$ F% g9 V2 S) }/ D
Z: n* R8 c5 \5 W/ c/* ROTATE_LEFT rotates x left n bits.
*/
% @8 k0 E! e# i#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/ o2 g4 M5 V2 x7 b+ @6 W
2 e7 A8 }+ b. ]' h( f) J/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
1 ? h% V9 {* r5 F9 \% | Rotation is separate from addition to prevent recomputation.
*/
& M# e. g6 M! B* T3 v& b Y, \#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
- L0 H- y- a0 N #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
( j. V' s2 g! `* ` d9 P, |) ^0 B; W) }% ]#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
" `% i- [; R3 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); \
}
; [: @& R3 h8 F A/ v
( ]% ^* T4 p; [- N2 U/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
& D/ \2 K4 e7 Z' z }void MD5Init (context)
4 v3 ~3 m+ j0 r" D0 O$ _MD5_CTX *context; /* context */
8 z0 T. Y+ v0 g# V$ W! P{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
/ K8 w8 f. [2 D. s */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
) ]3 w& d& l2 _% {}
: o% b$ n7 w* O3 t$ _6 f
" a6 T* n4 |1 r/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
4 ]# g: x1 y6 F U' r void MD5Update (context, input, inputLen)
6 Y" I) p2 U8 i MD5_CTX *context; /* context */
% P6 k5 {6 D0 n# H unsigned char *input; /* input block */
( X5 u& {' N2 ?8 ?9 }6 `) e unsigned int inputLen; /* length of input block */
5 l6 r: c& q+ w8 g) f{
unsigned int i, index, partLen;
! l1 S- [9 W9 `1 s! u
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
4 r0 G0 y$ w1 Z# H8 }6 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++程序


- w( |: W( C# V" M7 ^# \
, R6 Q7 I8 Y# `3 s9 Q3 q
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-9-19 00:29 , Processed in 0.056327 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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