中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
' ~8 d7 n' ^! Q }, U( i7 b- ~#include "md5.h"
- U' `, F, ]3 ~! G
' G% V- G5 m7 }, U0 {. {, Z/* Constants for MD5Transform routine.
*/
' p/ u6 q. ~" |' g" ?6 x9 o
; g# h: t) u3 ]$ p$ {' E& ?5 J
! b7 O: f0 P8 Y# k3 n& v. v#define S11 7
! v# c2 ~. N2 x0 M3 P# M9 x#define S12 12
+ Q5 @) ?9 N6 O* k" z #define S13 17
$ j9 P7 f9 V+ j# {6 R#define S14 22
7 P- {- k8 m1 `6 H#define S21 5
4 H4 O: t e) ^7 ^5 T: T! n2 D #define S22 9
1 y+ f; b+ `0 K3 t#define S23 14
% ~' C4 d& I+ a! z. D1 j# m6 X#define S24 20
6 {4 z- t* a0 P# ~2 u, w( C#define S31 4
0 C, g. [) H) P) s8 h% P/ W( O #define S32 11
- L, i. B1 l# t* z( x: ?6 N( p #define S33 16
3 \# z, P, `" R% q#define S34 23
. e3 Z# p! d- R9 I6 o#define S41 6
! Y1 |! E$ M. b9 e7 ^2 e& h#define S42 10
/ Z( Q% t; S$ O9 h#define S43 15
C# T" ]( n# G% A9 n: _: ?: Z#define S44 21
( p0 F" Z+ i, `# X! Z( J C
7 Y8 n5 `4 v2 _( ]) C static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
9 L, r8 S" N; L, astatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
+ P: n5 i4 ?% V static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
; M) U$ S/ B% Z [ z; A static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
4 T5 [% `( O+ e- S- A% @7 B static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
^; M2 f1 I) _6 W1 o
( ]! K; N; K2 D2 v8 S0 v' w9 Zstatic 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
. j: r$ {/ v( H' u2 n };
2 Y9 }$ c( P$ ~0 _8 J" G, R! W
; q" F% j& B; n$ r /* F, G, H and I are basic MD5 functions.
*/
) X$ |" C# N/ ]9 G# s- ^) R* _ #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
! w: o7 K# |2 h" x#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
8 x' `* q1 Q2 E+ ?: l#define H(x, y, z) ((x) ^ (y) ^ (z))
% O0 z4 p2 d; p$ l* B#define I(x, y, z) ((y) ^ ((x) | (~z)))
1 _' q2 m6 N" u# ~9 N3 m3 i
7 b! a& `" ^- }/* ROTATE_LEFT rotates x left n bits.
*/
% t1 E; L/ U* ]# v9 p #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
* }0 M. ?; q7 {! C* y
( f) O. _; ]1 S# Y% P7 X /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
2 z+ b0 P% v# f8 o Rotation is separate from addition to prevent recomputation.
*/
" E$ V/ r. c4 i" j+ T#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
0 D0 y9 J8 X2 Z* k( z( G% V0 t7 a #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% ~9 h! G8 D- Y#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
& b4 g# g8 { Y#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. Q n! n- Q( R1 m
' L5 M- B! t! K2 i Z# b /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
( ^ A* y% u, y; M/ X1 jvoid MD5Init (context)
. a6 n! X4 o {+ T MD5_CTX *context; /* context */
# M: D$ c5 N) z4 ~{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
' p0 w+ w% e! W& t( b! o */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
1 O- N3 G$ S+ Q7 x: h# H( y4 R }
1 s' m% u$ O! P0 P
1 P$ a+ `2 a' h+ J/ K$ D /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
( a* D& F6 p' S- i8 N void MD5Update (context, input, inputLen)
# x7 U' b6 j4 g) G0 A0 e3 i MD5_CTX *context; /* context */
8 W& J+ A0 i4 W: k' |unsigned char *input; /* input block */
8 D% _- d7 D0 j! e/ k( X( Y unsigned int inputLen; /* length of input block */
5 k O, Y, l( W# Q8 Z) X7 ` {
unsigned int i, index, partLen;
$ b( R5 n* T' t0 S% g" _) ?" J
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
- v1 x6 M+ X- P! H3 V6 A
/* 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++程序


$ C2 B. C0 M: Q$ H _8 ~% v
: ?" j$ C& F+ Q4 |5 B0 [
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-5-28 03:10 , Processed in 0.221847 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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