中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
, ]4 L- o! [2 }#include "md5.h"
+ b: B% U- M/ I2 A
; V/ W7 R" D( X: m" f0 R/* Constants for MD5Transform routine.
*/
* f, b1 ?4 B7 @% ~' u+ q
# n+ |' l0 p7 v9 v I8 V
L) s& S7 S/ ]; z) B #define S11 7
/ A0 r; R: R, W4 b2 B$ K& | #define S12 12
( s5 K! {, ^2 X7 B#define S13 17
+ A( Q. j- P9 k" I& J% K#define S14 22
& y) N' M; l) }: E0 L1 ]: l#define S21 5
) l" [ E. {- y6 V: E& S#define S22 9
1 T0 I u d* E/ m #define S23 14
& B: P, G- g# L #define S24 20
8 Y5 c6 }. c, Q #define S31 4
/ o4 d- R% o1 i1 P) E #define S32 11
?* L' \6 a# _/ m#define S33 16
/ b& ?) _7 K' O9 x5 @7 x" m #define S34 23
2 v, J; P* [4 \0 h2 b% y* s3 j# f8 J#define S41 6
5 G6 V" }- h& [ R- G. N# N, |+ z#define S42 10
7 r& c) `- @$ ^$ v Q# d$ B/ o #define S43 15
. o( Y8 r" `6 w8 e' v& ~ #define S44 21
9 [" K" m( W4 R9 G' j
: v6 s) P/ f, G/ h9 L$ h$ q, a( C9 h static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
4 s t" ?9 b# }# Sstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
, C) t8 O) r2 ^% c& ^. B) K8 Istatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
4 F) u3 Z* {: m& @+ y5 Wstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
! ?4 K, N1 z5 Pstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
% Z$ u$ W$ H4 N/ v' p0 { i7 r
0 a/ E% k9 i! D: cstatic 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/ i! {1 P9 z" |0 ~( J};
/ Y; X! V) ^# K$ G
% |& J. O% e& S4 J1 u u/* F, G, H and I are basic MD5 functions.
*/
, m4 K5 y. Y K #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
- M* k, j8 m$ o+ f#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( q. W7 V$ D) q- d4 J#define H(x, y, z) ((x) ^ (y) ^ (z))
% ?2 L# H! S* } #define I(x, y, z) ((y) ^ ((x) | (~z)))
% b' j* l4 _- U! o7 J- k
2 H* y" D7 V. e& M4 B! I! ?/* ROTATE_LEFT rotates x left n bits.
*/
& A p" D0 m' C) {6 w; H#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 E0 ?, g1 Y0 U/ Y, M+ u
$ w7 b6 H3 v, E: w! Q7 D: k/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* D' Y* y. D$ V1 R0 J- XRotation is separate from addition to prevent recomputation.
*/
- O3 h3 Z+ P) J# w7 } #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, M4 Q0 L" i. i: V! r/ l/ o#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, D# C4 j `; }#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% v5 t" H5 m4 u4 g#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
( z2 [; N# J7 @! r3 |0 e+ `
6 j9 \4 N. p( n" T /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
& t/ Z+ A( P3 O& b void MD5Init (context)
' K g8 P% e7 d! X3 D: B9 l! BMD5_CTX *context; /* context */
' H i0 F k, p+ \1 v9 Q5 ^ {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
~4 o/ l( ~" U: W- C*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
6 R, Z& X( t" W1 {( a/ G! @}
# }1 i8 q" s" z
2 v: D) W0 ?# q; @* _# } /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
" J& u! R, {7 a/ g$ X1 D jvoid MD5Update (context, input, inputLen)
0 G: _; t8 M$ e, I/ E5 Q, e MD5_CTX *context; /* context */
% C, D# a6 b) F, Q8 Z( Hunsigned char *input; /* input block */
. F# m @$ X7 C7 ~3 M, x1 d# Q unsigned int inputLen; /* length of input block */
' S. k* Y2 D5 D{
unsigned int i, index, partLen;
- M9 ^9 i! [- t& j8 J* |4 P' x v( b
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
6 ?, _8 Y+ ^; O
/* 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++程序


) C0 p: y: E9 ^. v! ^, c& d
+ ?$ [2 M+ {3 m9 Y9 y- O2 A
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-20 11:31 , Processed in 0.084338 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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