中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
: }6 ?. Y8 ~0 h( k# ^+ t' J$ p1 u #include "md5.h"
; h: V; C" A- H+ t/ V5 w" B: [" ]! Z
$ e0 P+ a$ }. C) R' D$ _ /* Constants for MD5Transform routine.
*/
5 c( e9 f/ G$ G! c, n/ r! O
! w! ]2 N- z z, B( B* D
' s8 C2 X; N" H: R' j #define S11 7
; W5 w; g6 t; I: M#define S12 12
/ v0 E8 y* k P% _# ]/ n#define S13 17
7 f) T7 Y3 r, R, ^0 O, x% b #define S14 22
8 u% M8 }+ s3 L* K& {& T2 G) i#define S21 5
- T. _$ T/ ^9 @#define S22 9
8 P$ M3 q* h0 j* s! q#define S23 14
$ N5 q+ M. ~! t4 R& d' G$ Y #define S24 20
' g& E& L# ?* v8 o& D% N- n+ X #define S31 4
7 G- J7 E6 f7 f6 F9 y #define S32 11
5 F1 _6 p' F2 }& O#define S33 16
% f( p. \+ T" D1 f0 t S #define S34 23
8 A6 z5 S) }7 \8 p- g #define S41 6
0 p2 x/ ]* V- F* g #define S42 10
0 t9 ?7 {2 _) Z& T9 G#define S43 15
# K6 D4 I$ n6 F' v$ \7 k #define S44 21
" l9 K3 {7 r, U/ H5 |
/ m! D. G- `1 kstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
5 X( n5 X' o2 V+ ~ Z4 u4 a. E static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
& B- p3 Q7 I# N5 Z4 A, G, {+ R( z; ustatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
4 o1 @! l$ ~% S% t4 ?/ C. w static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
& z+ Q/ j8 [) m" q; [5 _# M2 jstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
9 f! P+ O& n! A& l4 o) D& o
9 h' u" c( ?8 }5 |3 i. `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
) S! D9 m( ]# ^8 t% R/ G };
k7 J. d4 m6 ~8 x( D& X
( q1 ~. P: |% _7 G# i- v$ Q& m* s /* F, G, H and I are basic MD5 functions.
*/
" s9 u9 t3 ?9 Q#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
: }# R$ {; m) T& ]. D' o3 m8 C) V #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
! T; H2 H+ z9 u. \6 e+ G: z B' D% B #define H(x, y, z) ((x) ^ (y) ^ (z))
6 U. U/ \2 a# @5 F+ J1 e#define I(x, y, z) ((y) ^ ((x) | (~z)))
' T& B' d) s+ {4 l f( W5 z8 _
0 |$ ^$ w8 F* p2 Y% t7 D/* ROTATE_LEFT rotates x left n bits.
*/
' t+ A/ D" P% N#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
# }- V3 r' C' `! H1 d
) i/ r2 E) O |( v: A* A /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
$ A3 m% H. L9 O/ T+ I5 ZRotation is separate from addition to prevent recomputation.
*/
2 | M8 k' x7 O8 J! X& v; n4 d#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
2 ]/ n! e! [# M0 P, M. R/ q5 t#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
3 i$ [, ?7 V2 w! c #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
( h' H8 c' D" @8 M% v #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 E) K, T( ^0 X, k& A
+ j1 o- X+ a# [# _/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
+ L. V' l) W8 ?- wvoid MD5Init (context)
* n6 W' c) a' U- T MD5_CTX *context; /* context */
; k# j8 b2 K6 B) D0 T8 z{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
4 C- F) E8 [) v5 r*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
/ H/ K) z L( a, @}
( K& M/ s( |: j9 X5 q0 c
. h1 G) B8 k0 c: [$ H; H /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
, R/ p) w5 |( U j8 Kvoid MD5Update (context, input, inputLen)
7 U" s7 [# m9 ^# eMD5_CTX *context; /* context */
* Z% q6 a2 m/ e6 {" [) funsigned char *input; /* input block */
+ f* w$ U+ T5 z7 K- n& hunsigned int inputLen; /* length of input block */
+ v3 J& C7 j; i' ~3 T' z9 `{
unsigned int i, index, partLen;
* a7 h$ h+ f/ m$ Q( o9 M
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ {" I$ M$ G8 A( S3 i' C
/* 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++程序


' }9 o) u9 i) E" N6 c7 m3 M0 _
7 {% q& x/ V u: L7 Q
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-28 14:54 , Processed in 0.056076 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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