中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
$ C6 U2 d) N- @) ]0 p# c" J" O9 w3 [#include "md5.h"
% O' |) Y. y7 c' V e
6 k! j% I+ y0 w /* Constants for MD5Transform routine.
*/
% ]5 {1 e6 O' E& S$ H0 ?7 `3 h8 S$ q
" c8 d* T/ f# g
5 C& {% t1 U; v5 n l/ o6 U) P #define S11 7
0 I. W$ N% s$ V5 E& Z& P#define S12 12
m: p( A# B9 w7 t: } #define S13 17
+ \0 q2 t% A; R. [ #define S14 22
( }0 e% l3 x( }8 @7 T#define S21 5
9 A$ N" J; ?4 e6 W7 @ #define S22 9
" Z3 d0 b+ l$ Y- L; O#define S23 14
4 l: f) T: P+ J8 f% Y #define S24 20
; W$ u+ f* ~: n7 r#define S31 4
5 y6 w! o$ B" D: ]( E2 |0 A0 G#define S32 11
( l) v/ B- o3 S* H3 ?#define S33 16
; e/ w: M+ K T$ e9 R #define S34 23
; `' Z2 i: H) R/ @2 Q7 w- i* V6 H #define S41 6
8 \6 i' I1 h+ v' e2 ~- M3 M #define S42 10
4 d6 @6 x$ N) X% } #define S43 15
7 ]5 }; V7 U. R% u#define S44 21
2 ^: w' a0 \; V' p. U6 V# _
! k. \& k/ c* C6 c: z! y3 bstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
$ i) m9 h$ i9 o& W. x; B static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
; h9 i9 v$ E: S static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
/ j; X( ]& I. R0 F static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
8 [4 d6 H. G3 V% o$ c static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
/ ?: r' {) ^; Z; r* \! u
$ m7 r+ b+ x0 M: S% G4 f$ {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
& o, O% k: u/ |& }};
6 Y. C7 I& A: x* D# w, N+ b' U
( _$ L+ h, _/ d9 x/* F, G, H and I are basic MD5 functions.
*/
9 A. L8 ] h6 \: u8 n #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
3 f0 `+ e2 t4 U) H$ Q- Y$ F$ T#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. B3 z( f% F8 M$ z( ?#define H(x, y, z) ((x) ^ (y) ^ (z))
; l: I' b f3 V% h; x9 ] #define I(x, y, z) ((y) ^ ((x) | (~z)))
8 n; X. \# \6 a3 V* j, o4 X
7 } g9 y, v; o; R* ?5 I& |/* ROTATE_LEFT rotates x left n bits.
*/
4 L6 \. V2 D, `% \ C* g#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
0 {- Q7 V% `( |7 d# B% X P
2 o8 L0 w/ {9 \: r4 u /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 l- }# ? O" f0 Z+ g+ y+ MRotation is separate from addition to prevent recomputation.
*/
& Y; ?, T* Q8 X4 J #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
/ I, @+ ^. p# j# {& k' n8 u9 ]#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
5 }( B8 Z" v) c& p- h, \3 C N7 | #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
- ~5 Z! y( z, r #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
. B" v$ Z$ v% _( ]
8 L* W% O S" v7 x5 \/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
+ H# \; d9 P4 U; C5 D( bvoid MD5Init (context)
9 o9 w# y! d. r& }% VMD5_CTX *context; /* context */
. [' d7 c/ H5 W) ^ {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
. R% V+ Z1 C2 N! s9 T' S$ y/ x( W */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
. M% i5 T1 m) Y8 ` }
" {, A' g$ W U6 ?- H+ X
$ Q( \$ H5 z( i7 d( \ /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
; U v& L; C8 C void MD5Update (context, input, inputLen)
8 O/ J4 T) z: _3 C& SMD5_CTX *context; /* context */
+ l: |9 A, C- Bunsigned char *input; /* input block */
, H' `3 Q9 \& a/ W unsigned int inputLen; /* length of input block */
, o! l+ _6 S& Y) S: l{
unsigned int i, index, partLen;
* x: o& e& [7 M: z0 _- i
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
1 P1 F5 `* i! F V# \
/* 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++程序


" S9 P4 h) C* U. L3 q
% z% } }3 E4 d' x
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-7-10 16:45 , Processed in 0.266330 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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