中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
) \ s2 c, f% D" g$ f #include "md5.h"
5 N" j( `6 q, R& Q, o" z/ \
' ^- {4 c5 [) l/* Constants for MD5Transform routine.
*/
4 R* N5 E0 Z( S5 P+ w- F
2 c+ {3 H# r% j
# q6 A- s& w- j C- s #define S11 7
0 |. H. g$ v; s: _#define S12 12
, e: C5 M0 j3 \& h2 j* ]. [% V #define S13 17
3 \: L8 U) B. D. J- S3 ^ #define S14 22
( {! k8 i( R1 J0 H# s% D7 ^ #define S21 5
& w) _. e, e; e #define S22 9
5 v7 N! m) B8 i9 _" A5 X #define S23 14
+ z) K5 |4 E. o, w _2 o #define S24 20
8 b2 F' C2 e, _% L3 }#define S31 4
. r7 W% m0 n* v u; A6 W#define S32 11
# j2 t# ?( ~: }- b4 C- t! M$ g! }#define S33 16
! a' U3 B d( C#define S34 23
7 ~" |; |0 D8 X% h( @$ n#define S41 6
/ Z4 U6 S! A% b! m0 O#define S42 10
5 y* S/ F0 k+ q- T, c; q, Z#define S43 15
[- z8 d* u& O9 p% k; v. o #define S44 21
4 A' `$ Y" t# w$ Z# t: u# b% ]& a- @
( _. x$ j. H3 a. u% W0 f: v- j& Xstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
+ Z& M% G. X8 V; q lstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
8 q6 u0 n/ y1 O1 K; O6 @& Qstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
( ?* M5 ~0 W1 L+ h4 n$ I static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" h0 N* }2 v. o static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
. ~4 d, d' o: b" t
9 S+ y7 o4 U, a- Z C$ Tstatic 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
* C+ J3 @9 j3 D4 _};
0 n( e& H4 p% Z6 f4 s
) I2 s4 v' D3 F) d; H/* F, G, H and I are basic MD5 functions.
*/
% J. w" K5 w G4 @2 Y8 H0 _5 |, l& P6 z #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! X' f3 e8 K* U. }0 g #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
* X# n, f& o/ l* W#define H(x, y, z) ((x) ^ (y) ^ (z))
( ]3 R6 ?& B8 f#define I(x, y, z) ((y) ^ ((x) | (~z)))
) c" L" i$ G, C L
5 o% b I! |7 ^4 t0 W/* ROTATE_LEFT rotates x left n bits.
*/
0 @9 s8 y1 U' O2 `#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 d* A; c! U& b+ Z$ J! ~3 R- c1 {8 ]
5 l$ B" Q( ]7 p: c+ V i /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
: \- x. z& Z5 K$ O2 B- ^- X Rotation is separate from addition to prevent recomputation.
*/
n1 i$ [$ V9 m#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 ^" f- S/ J' j, w. Z#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% e0 b( F* _( I#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
) \) f- S7 g7 v1 s4 N ? #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
7 j: k" m' R* x
1 ?2 H% Z$ D1 Q0 w/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
) a+ u. S* S# v- @+ O U void MD5Init (context)
6 ^* m) W: v( K2 I! Q0 L" @MD5_CTX *context; /* context */
5 j2 P/ q ]/ S: K" V+ c7 ?; G* q{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
5 c- \1 q8 k! V+ d8 m*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
9 Q7 W( e( O2 C2 r" d, J/ W}
, |* ?9 `7 J/ n) q, c) N" j; c
6 L( U0 ?. F4 E+ |2 i/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
: u: g: L+ _8 [) Lvoid MD5Update (context, input, inputLen)
& @$ F# }: E: C8 B7 ~" r2 f) y MD5_CTX *context; /* context */
& T& I |; A0 Q: P8 U unsigned char *input; /* input block */
. {# I1 s+ C8 X( n9 c unsigned int inputLen; /* length of input block */
5 J# h# ^6 h* B( ?/ p) k {
unsigned int i, index, partLen;
/ Q/ Z# l! i* J6 y8 l2 D, I8 ~& E
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
0 ^7 f! G, ]$ @9 X1 `* t2 @% 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++程序


( |, k8 ^6 x9 l$ L% N
! }0 J& Y, h( G1 d$ X; Q; D
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-15 12:49 , Processed in 0.068234 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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