中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
# ^6 Z! y# |6 q8 y% @1 p #include "md5.h"
* H& S! t, }: Q
% n0 O `) z& H& m /* Constants for MD5Transform routine.
*/
& K* z: j) C; k: v) r4 B; s
3 I5 p7 C6 s9 f& J
' _4 g3 _( W/ t( @- T+ V2 X; B#define S11 7
& \8 Z" s( W+ f, `" S5 d6 u#define S12 12
s9 j0 f/ z* O! d0 I) [9 c #define S13 17
: t8 U3 \, o* b7 I1 {/ G. g% A#define S14 22
( P o0 j# e$ B1 m8 s #define S21 5
' |3 V8 k6 {. E #define S22 9
- Y$ s2 }" T3 Y( y: @) F% ?#define S23 14
* T* D8 J" K O/ L #define S24 20
; U. `1 e1 U, N e) [ #define S31 4
2 R1 s, z" J. k5 _#define S32 11
, v, ] Q4 Y% L* ?; v6 I6 R" J& S #define S33 16
5 h7 \0 ~1 G& X" K- i6 H" R! I#define S34 23
L2 o9 F. v$ L) D$ ]. N #define S41 6
3 u/ P+ ~8 B# c6 x0 J#define S42 10
6 H# y$ g8 Q7 k- I$ G/ E( P' }7 M#define S43 15
( m+ t8 x. ~( \& L2 d7 x t* Y#define S44 21
7 C# H+ z# v* @ b/ Y8 L; a
! N( Q3 ^' s3 G0 ^+ {4 Y3 y- [static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
# [7 S+ e, ]' \1 Ystatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
3 R8 |& G2 j9 U/ J- [% Y static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
" L+ {7 r& Q$ E5 d. m; H% Wstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
' k+ Q! ]( j9 q x static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
0 O- e4 Y6 V; D7 Z6 k7 ?/ `
# U0 v, X3 z8 z w2 Q7 g' n) ? 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
; S2 j; L: ~" Y! A3 X% a" v };
3 S3 ?6 S7 {1 e& O
x. d' E$ D/ y /* F, G, H and I are basic MD5 functions.
*/
# _) @4 u1 |6 w- s) K #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
2 W- \& A5 U$ m& n& z#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
) V' L* c7 x8 b) G, b1 L) ? #define H(x, y, z) ((x) ^ (y) ^ (z))
B, H- f3 A" h" X( s#define I(x, y, z) ((y) ^ ((x) | (~z)))
: j; | C6 H( J$ Y% q$ d+ w8 f e
7 N4 T! l+ ?6 Q! P. o4 o /* ROTATE_LEFT rotates x left n bits.
*/
. }6 h; E* E" i$ \3 q0 ]% d- `) ]3 _ #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
f# v: w# K z+ v6 N7 |
. ?8 B x5 ?2 c/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! X$ n4 l7 }. ` b, dRotation is separate from addition to prevent recomputation.
*/
- S. W/ i: n% ]" D9 G. N8 u#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
{8 i$ k# }/ i6 |- {#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
6 ?- {9 Z" d+ R: n#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
: i6 G; N E; g* `2 M; U a #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, j4 T; k2 }4 _* H
/ z# p c& ]1 A/ ]( U" a /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
! }5 w8 k$ n$ h8 s% t8 g void MD5Init (context)
3 q; H9 ~* |, Q, K7 t MD5_CTX *context; /* context */
5 s4 f+ U; j, g8 }, O0 P8 \& i {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
* `$ U' n3 {7 _' Q( T% p v*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
' \1 s, E" w4 ^- C0 p5 [+ Z1 P }
- y2 f/ X7 P; S P4 r: _4 I. C0 ~! M
7 }: X1 Y6 }( U5 v: ?# I/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
& i: `" X' T8 M/ i* p# O0 g6 S1 i: rvoid MD5Update (context, input, inputLen)
; }. C( G* x8 ?" i& UMD5_CTX *context; /* context */
" t% i1 e7 ?% G# g4 l unsigned char *input; /* input block */
7 b9 B8 e' a6 B, m6 H6 punsigned int inputLen; /* length of input block */
& d |* a$ C" a& `2 K% q2 C0 A3 E{
unsigned int i, index, partLen;
' x- C: i; b7 X
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
& Z) I+ s. k& E; Y8 W4 P
/* 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++程序


2 r$ P- q* {3 T9 A1 z+ k' F
0 m5 e) `7 ^ r& ?5 m* F( b
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-16 15:55 , Processed in 0.059971 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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