中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
5 b% d8 G j2 d, |1 ?+ M6 s' Y* ?#include "md5.h"
B4 r1 N7 v9 T3 x5 z
* s6 y& D. m8 }6 `* H9 n/* Constants for MD5Transform routine.
*/
4 D! T3 r4 O, x# y6 I+ \/ l8 P
9 @/ @; t" Q. ^$ F
% o$ q. F4 a' {#define S11 7
; S H. O" f! s7 m f#define S12 12
# d& s- r9 d/ K. n$ |% V' K #define S13 17
$ L4 N( x% u9 D, G$ }2 G#define S14 22
/ ^0 g: m) Z' j5 h #define S21 5
; I0 N! O8 [: H1 E4 M#define S22 9
+ I9 X4 ~6 y3 K) Q* |; [9 d #define S23 14
) {5 P$ |( P6 D#define S24 20
7 j5 c$ c: P, d #define S31 4
8 u, [4 | O9 L! X#define S32 11
3 I3 o) F# r1 w$ X( t! r #define S33 16
( u3 |) m9 I7 g5 A S3 x #define S34 23
" f+ A% l+ B! J" E2 m #define S41 6
8 \9 I; p r& l- C#define S42 10
1 x v3 A1 s" o% A' P/ O7 k+ W5 K #define S43 15
' B7 L7 F& Y# m5 w #define S44 21
# N8 C+ U8 Q- X
& t+ W5 H0 O$ O( A static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
( d. @0 z6 u$ Ostatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
; W( z5 c" y/ }9 @6 h9 nstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
5 q* X/ T0 R! R7 S- j7 I1 t static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
' t2 j+ s, B, V" z, O6 j. ?; Estatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
9 _9 ^, c& L- T9 ~: u
" g$ t# W5 u, w& \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
/ x. D& }/ {' X2 d3 C};
' R; f2 T1 k( F* g1 L
9 f0 Q7 _, ^4 C3 M /* F, G, H and I are basic MD5 functions.
*/
' _$ A) ~( m6 Z! M `% }1 M0 b' x #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
( M1 V: j6 b1 _. ~% e6 L#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 ~, J' i! {" x, a/ y, d6 P& `#define H(x, y, z) ((x) ^ (y) ^ (z))
1 C9 Z1 G0 `1 r6 I/ L2 S) ^7 x" I! Y#define I(x, y, z) ((y) ^ ((x) | (~z)))
8 D, f6 Z9 @7 R( J1 x5 C, M
. I, z3 L0 H) y/* ROTATE_LEFT rotates x left n bits.
*/
$ p) w9 `1 V2 y. |: x/ `# P#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
& _! Z% E. o( _$ I" y
& K( G4 ~, \2 X: l1 z* Z6 d& C/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ |7 X V) A( yRotation is separate from addition to prevent recomputation.
*/
- d9 N' h2 ]; y2 u5 Q( [# w#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
* M" b% e/ d( v #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
. V3 I7 Z7 y/ k" [ #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% p* c+ b$ ?+ k5 b) V# {4 | #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
) K" v: V4 P# q/ w' r E8 V
. _- N, t" I( ~; J* L( G/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
' d+ s- P7 t" g void MD5Init (context)
- f, a+ U Y6 _% t! |$ {; @ MD5_CTX *context; /* context */
0 X& s& `& ~# x7 D{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
2 Y6 i, n b4 q. p5 F*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
! s3 e* \: R9 f* m}
8 i; I3 E' p! L4 i, b9 r
2 R/ w( z* }; `) r( B+ s# L; j. ` /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
8 [6 q- g/ c# R; Bvoid MD5Update (context, input, inputLen)
' c! r. O' Q. A7 \MD5_CTX *context; /* context */
# x4 {3 k* ^) ~ unsigned char *input; /* input block */
P t6 o; M# }4 D: Y" Tunsigned int inputLen; /* length of input block */
3 C: f0 u0 }; L( B{
unsigned int i, index, partLen;
& B h% [/ q% L/ G* y. i
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
2 w, }# L) _! N: @# y: i8 T
/* 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++程序


% h7 x$ g! }# Y. R1 |
1 {% X. y6 v. b; j, J
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-9-21 21:49 , Processed in 0.118350 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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