中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
# c5 L: y; Y/ u- H8 a#include "md5.h"
4 Z3 H# Z* f& d+ F
; w7 `# Q0 }. {& W5 X1 g/ } /* Constants for MD5Transform routine.
*/
# t5 ]4 {5 H7 o6 O, }0 w( u* G# a2 D
+ u, V6 Z8 x U: G) y h& r c
* q1 ]: _$ f/ l2 v# s; f i! V#define S11 7
- O$ B% Y' G/ x' n#define S12 12
4 r/ q; r) S2 |" Z* E #define S13 17
' \6 U5 K) N$ ?* u2 }; F) {% Z#define S14 22
, ^( N: f6 {) x% y#define S21 5
4 a$ j* C" U: F% X! ]9 z3 h* E#define S22 9
5 B. U+ [( O6 o, F8 Q8 P #define S23 14
5 e7 B4 e5 W* c: R #define S24 20
7 |- W; D! i: [0 T* v. ~* B #define S31 4
- X8 @" E; e. R0 \9 P#define S32 11
5 f) M2 j# J; L6 n# t& N #define S33 16
/ M* @, f' l' M7 n9 b#define S34 23
6 i; l. l: `5 [ z% y5 r6 @! m#define S41 6
9 }% r$ @( o' O) f#define S42 10
4 ?: n$ k; e+ v* A #define S43 15
9 h8 R5 y7 b1 T' C/ e8 J) B#define S44 21
8 J+ f6 f# K( a5 j
5 j) p3 w/ U O V: @# pstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
8 r* }& s n3 `4 P K# g! Ystatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
P: k; S. ^2 @9 t2 R% \ static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
' P+ J5 V' u1 c0 Y8 }! _( _static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
/ J9 ~% z' M: @; @* [2 Z static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
" n) f+ B3 L7 O$ k% I4 ?# H3 O$ M
- i0 s+ g5 ~) X( }$ Ustatic 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
1 f; E& @+ r, v1 h4 S% y};
# {1 T7 O7 o' Y1 W
- D% U8 |) X( J$ R5 m2 r( ^0 V /* F, G, H and I are basic MD5 functions.
*/
6 m) p+ K# y! w6 r7 N" J! |#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
" }$ K/ F* {- A' X& s: ?0 |7 ? #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
' D9 ~% t) V: \* M, d% w #define H(x, y, z) ((x) ^ (y) ^ (z))
8 C1 F! o3 R6 m# m+ T# y* e& W #define I(x, y, z) ((y) ^ ((x) | (~z)))
! k J* M& Z6 }& q
/ f% W$ S% e. p) W: d/* ROTATE_LEFT rotates x left n bits.
*/
9 X7 A! {" C9 M1 L$ Y: A #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
3 y8 W0 @1 l) {# P. k
9 \/ f9 C# s- j; k/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ N* ?4 x# X* s% F$ K Rotation is separate from addition to prevent recomputation.
*/
: G7 X' ^1 M* g M, b& 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); \
}
* X; I) d1 |3 n: C4 h# G #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
1 ^) r, I r0 K& H! @* o' B #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% S2 f& f( z* f' \#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
5 `! w2 Y' I# T
% d; Y3 }) n0 K; }) X f/ R1 [& R/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
; U) X( \7 I" O* G' u void MD5Init (context)
( t ?# ]9 r2 X4 w8 R8 SMD5_CTX *context; /* context */
. B @" ?# a7 L1 e6 G& f1 X& F/ P {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
2 q- ?. Z- @; E5 `* B5 i: S0 R */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
* t5 o' a/ A; a' V% g" m }
5 V7 a [4 Q# Y
: n5 W G0 D, h& j" H9 E /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
4 z! M* ?8 X, i) S4 a2 u void MD5Update (context, input, inputLen)
" t& ^$ H5 U6 m$ e5 [ MD5_CTX *context; /* context */
/ A3 [& ~8 E/ j1 b+ r unsigned char *input; /* input block */
; J Z# f U) d( E* G( B7 T unsigned int inputLen; /* length of input block */
* W* O T, \9 h9 n) \# C8 S# Q{
unsigned int i, index, partLen;
- n3 V. a) r z+ l3 d1 Y0 a
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ R X! y( J- u/ A( k; [7 q
/* 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++程序


. ?, S4 Z* X# _% r' ^* |3 o
4 A! g% Q$ r5 {" Z# D/ V
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-16 11:35 , Processed in 0.348883 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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