中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
& ?! h* H2 t( P! b4 J1 A5 ` #include "md5.h"
: {4 n3 K6 I2 }5 C" i- }" H$ z
9 _- v! f+ O3 R& }/* Constants for MD5Transform routine.
*/
E4 M+ p; c& P3 {0 K5 ^
" x, Y+ u% ^0 j% V
& m1 o8 ^* |( T6 C' K1 `# _#define S11 7
y6 u7 d" F" }. z- i3 J& U8 {2 @#define S12 12
& ~. A- d& ~3 q #define S13 17
3 ~" g3 ?" j. ]- P% i4 A#define S14 22
% c( n+ e5 P3 i1 V/ J1 s3 u, V0 V6 B#define S21 5
2 w5 L5 z. b, W+ V, z. x #define S22 9
5 C1 o3 k1 J$ D% o/ W #define S23 14
/ r7 I& S; I4 _* F& E$ w #define S24 20
& T* b! Z: ]/ H1 T0 _8 w! D#define S31 4
, w7 g3 y; ?& }! L. D+ m# V0 D$ u/ \ #define S32 11
2 E- |7 X: b9 J9 k" F#define S33 16
9 ?; x3 _6 [# q #define S34 23
0 P# A1 \& K$ X #define S41 6
0 P; q" W3 m( N G. o. [4 N2 S#define S42 10
" e& q$ _ G: l# A #define S43 15
9 ?8 ^* U6 E2 Y) @& m5 t#define S44 21
1 K! J: C# B. K0 |6 f0 g
: g1 s; [: ^% k4 Z) M7 L- g/ p static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
6 d6 @0 n3 |. N6 wstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
; [ y) `$ c% p9 Z' i# P+ Y+ b static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
4 M9 f# C9 u) l; F* b n static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
( \5 |9 I0 @" O$ r+ _static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
1 S% k) ~; G; N d
( s2 D) ~ s# |' T" v+ f# dstatic 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
3 P' F; [$ n4 F2 i$ L};
. f( ~& |$ m f( X. p+ d
C, Z# r6 K9 E0 s |% m4 T /* F, G, H and I are basic MD5 functions.
*/
7 Z# e2 g+ r- u( K$ R #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
$ k2 s8 i4 h" Q$ c#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
. v$ |/ m, g9 B I #define H(x, y, z) ((x) ^ (y) ^ (z))
0 }, h/ a8 L5 I" _; d0 U$ I. g#define I(x, y, z) ((y) ^ ((x) | (~z)))
A" ]( G" C1 S2 g( H
+ J4 x, m: ^8 o- \! C/ w. f/* ROTATE_LEFT rotates x left n bits.
*/
/ L: l [ s* h4 S0 @#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
! y/ A3 @) c. N4 {
- I: h4 {! O, s4 K! R4 B8 e/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! N0 P! K9 m0 K4 [8 h: N) B7 KRotation is separate from addition to prevent recomputation.
*/
9 V, Q0 C. h- [' w# l+ \#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, r% j3 J4 Y+ n) P #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
x/ K \2 w( o0 O#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
) K' g/ f8 U2 [* V. c. t#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
: ?# d9 b. V( N, r3 c3 f
1 J8 S6 A; n5 K3 M# {- F+ x/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
8 [, l0 y, f! T5 u G void MD5Init (context)
; g& F* w6 X7 Q, _; r; P MD5_CTX *context; /* context */
" t+ c) l+ f5 i c) | }4 q {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
$ ~1 M+ u3 j; A( C7 T */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
+ D4 a7 h: `1 S6 C}
, B( D" U, [- A: @% ~
$ r& c" v+ c- d ~/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
6 J. a2 ] P6 ivoid MD5Update (context, input, inputLen)
: o- c+ z( g' x( q4 L# u; Q# Y, gMD5_CTX *context; /* context */
3 R# k3 i* f& u2 B! J) M9 b unsigned char *input; /* input block */
; C$ m( _$ B5 c8 lunsigned int inputLen; /* length of input block */
; L* @+ F3 o4 l# r* x{
unsigned int i, index, partLen;
* w4 ~% u# r$ b9 z8 a6 R
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
. Q, d6 B+ q' k c
/* 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++程序


`: [$ j! F# B. I5 m
- K& f6 V3 ~8 z+ K. J/ R/ q/ o: w
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-9-16 16:31 , Processed in 0.055269 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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