中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
+ d5 y8 w2 I1 B9 ~/ {& U#include "md5.h"
$ A R) t$ o# l/ Z2 {# ^& w4 ^
: O5 A% y+ S$ Y" o /* Constants for MD5Transform routine.
*/
. o) e w* y: }- W# \
]- N4 H( b' M( x5 A
, w0 v6 ~# ]/ G- o, c# O# ~#define S11 7
& j4 w" Q- l. d1 W# G4 Y" K#define S12 12
4 s3 |! q7 S! Z #define S13 17
+ }& {* l5 ?7 f& h% X' H #define S14 22
8 ~* G; {& D" C$ ~#define S21 5
7 u9 K0 e8 w. ]% m7 e. `' ^) z& j( q- w#define S22 9
* r' o. n2 b; X" a #define S23 14
$ P+ l, y* l, r0 M$ o* ?$ y: A5 H #define S24 20
' r x7 w' V' a; M* \; d#define S31 4
* b' {7 J, _" y#define S32 11
3 J6 t' n1 P+ E: i0 p. W' z#define S33 16
/ V8 s$ H4 @& g8 q0 K( k: M #define S34 23
3 @) N. L6 o' `$ x! m#define S41 6
$ T0 X; L5 H1 X: @#define S42 10
( r2 P3 K2 v) d, H1 i9 W) }#define S43 15
7 ]$ y2 @+ D* v' D, u: r #define S44 21
' F7 {+ @' z7 `' u, @
5 D2 y y2 y0 y: _" d$ e static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
, H g2 r) H. l7 s! n3 Wstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
9 I; ^4 U% O' [ Y9 n# q5 W) c static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
* N! R# x+ o6 r% x4 f9 w( F& L static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
c7 |" C4 f2 A: gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
& }( R$ g8 D5 ?6 y
2 } Z' x! N' i. 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
! |4 O* \1 [9 V6 o" |% |# A$ p};
2 }9 V! Y; P1 R" p/ `7 h
% R% d4 O2 P7 P/* F, G, H and I are basic MD5 functions.
*/
* T" {* J% \0 Z #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
. C- |, Q& P9 s2 G! \& Q; z( N#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
, U* ~8 w6 H9 t2 o #define H(x, y, z) ((x) ^ (y) ^ (z))
$ a9 B) ?# n G #define I(x, y, z) ((y) ^ ((x) | (~z)))
- h* W( b: i+ P. _6 W0 T
: a0 ?( g0 [* M; Z B2 }3 g /* ROTATE_LEFT rotates x left n bits.
*/
7 c N4 @* ?3 Z, H t8 Q2 {#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5 b. ~2 M0 C1 A _8 [8 N
2 k) R, x% }1 w" ^" Z# u: o/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
! R+ S/ A! G6 ERotation is separate from addition to prevent recomputation.
*/
5 K# f. K$ N# R# M, O7 C #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
' t | S/ N) a& l! F! I X#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
. ?0 w; L6 I6 |4 z#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
$ y* \( Q! ]4 m3 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); \
}
% u/ C% _+ r; C5 C/ V' M
5 a4 N2 e8 I i+ m8 M9 Y/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
5 b0 g6 `6 k% b) [5 A9 jvoid MD5Init (context)
3 \% u) z" {1 V/ E) c" u6 C MD5_CTX *context; /* context */
) H8 d- B+ S5 A* ] {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
' B8 ^/ J6 z+ }: b */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
' P* n: Q$ m6 t3 B4 @* Z}
4 S$ K- d) R H7 k3 p
0 X& A& |! U% L/ f, A /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
8 X: `+ ~0 K, D& F5 G1 j void MD5Update (context, input, inputLen)
5 R3 q3 Z5 F; bMD5_CTX *context; /* context */
! N8 C3 R+ D8 p; `! S g unsigned char *input; /* input block */
* m* \* U. N% |. F, Iunsigned int inputLen; /* length of input block */
0 s! n5 r( e r* V. B2 V {
unsigned int i, index, partLen;
) C% U4 z) P/ H! L
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
7 t; p+ k5 f2 [# R4 B! v$ U1 L; @2 E7 e
/* 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++程序


, T; p: y5 P0 m1 X4 ]: D/ }0 j! s
2 X9 T4 z4 G8 T
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-7-4 19:55 , Processed in 0.077275 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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