中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
9 r- H* P5 J4 e5 W. H #include "md5.h"
7 e. t1 Q' h+ q1 | _- j
3 P; ^5 ~! a6 K$ {/ K* B /* Constants for MD5Transform routine.
*/
# I( G3 R+ M0 o! k% c
* U, p' u5 E; k8 n1 l4 Z
! J& M8 z: C, {3 U( R% S* ~#define S11 7
. L+ i4 z' Z7 v9 L7 _6 s5 p#define S12 12
9 ]4 Y+ P' _3 s( W& t#define S13 17
" c' [! m( L- ^4 j/ C3 O4 d#define S14 22
6 R9 [# W, {( f #define S21 5
) i. V7 ~/ N3 z: e. M, S7 \8 s#define S22 9
c+ U$ T) Z9 T! g2 \- u#define S23 14
/ M% S5 f7 |: \/ L#define S24 20
1 O( z T1 o6 c# Q O* Z$ } #define S31 4
' S- I$ j- b2 A x#define S32 11
( I1 B5 f4 \/ E' O2 x) o#define S33 16
& B c9 n& @9 v6 S8 y5 h- e#define S34 23
% u) ~8 X! w( u9 e#define S41 6
- y1 [; ?% b4 ~8 t; I& \#define S42 10
5 g, j8 s, X+ l #define S43 15
, z2 m7 ]& J% O) Q' @ #define S44 21
# v3 ]& b5 n$ O* X: Y# `
8 ]$ S. B* F3 f+ ]. M9 rstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ [- o" n2 x7 X' h/ \1 a" B static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
+ b; ~+ B4 {' } static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
4 |2 y Q; |. c+ f wstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
: {8 {4 S k8 |7 N% K) Ostatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
" g/ x, g" @# B
" L- y, v7 \8 G( P0 Sstatic 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
# r) _0 U- k7 e7 W; u };
/ G7 c8 S% [9 l8 Q
0 y" D' T+ ]* A, N/* F, G, H and I are basic MD5 functions.
*/
/ C. n4 o; v- V4 h #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+ t$ X/ ]3 b2 W& n! I$ B% {#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
! t- b. O8 U7 I+ r$ T9 d: b ]#define H(x, y, z) ((x) ^ (y) ^ (z))
( \- T3 X& `. H8 ^5 I/ n#define I(x, y, z) ((y) ^ ((x) | (~z)))
3 N" B" Z8 g( A( C8 A0 y
0 O1 W: K+ Z8 A( I /* ROTATE_LEFT rotates x left n bits.
*/
" J# \6 Y* F+ d) w #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
7 l6 x: s0 E, ?8 j0 g" c$ \
% _" m. E' s3 T" Z$ B0 H* l- \/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
) A. x+ w- r) g A& RRotation is separate from addition to prevent recomputation.
*/
0 E" p- [/ G$ o7 z! O#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
. S d" d+ H4 { P+ y #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 Y* W3 r3 G8 w! g& [ #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
4 } v6 b. q: j #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, o z! R8 y6 f! i; B
& K$ W# f0 P' i& B( J7 w /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
' r% r" d7 J+ V. ^1 M4 R- P8 g void MD5Init (context)
2 {) ~* H7 Y* Z. dMD5_CTX *context; /* context */
: W% ~4 c$ K9 ^3 s- S# ~- P1 k{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
% I# V% E |9 T*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
! R" }/ L* Q# v9 s" H }
5 k7 e, A6 O- b; L& U; `
, y; e* O H) [! N/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
" K3 q& {& n& `7 w1 \$ ?9 Wvoid MD5Update (context, input, inputLen)
% U1 w) ^$ h( uMD5_CTX *context; /* context */
) h% h" c. T+ G b* u. \0 C& s" Munsigned char *input; /* input block */
( L3 {2 o$ W/ a$ Ounsigned int inputLen; /* length of input block */
1 T/ r6 _$ ]4 p# ]- y {
unsigned int i, index, partLen;
$ Q: f2 c) S8 Q I1 q y1 }5 o
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
9 g! |# v# ^; F+ F+ N* @ 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++程序


0 D' u; e( `" S) A
' ~8 _- J$ L- B: B9 l9 l
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-15 02:21 , Processed in 0.058930 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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