中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
0 [8 C& s& j# h2 t7 K2 P) {; k1 [; H#include "md5.h"
+ m* }6 S) R: @ Q
/ K z9 X' n- H+ B* f/* Constants for MD5Transform routine.
*/
_& I% [! }6 w( s0 P- `$ Y1 r
& s \+ ]# C7 E% A- r4 p. J
+ F7 ?3 v7 B3 r9 J) o1 b/ w( ?#define S11 7
$ h1 d* ~3 J7 O$ ^" ~( M. s6 U& f. ~#define S12 12
8 V( a. A8 U$ O' X$ F+ V2 G #define S13 17
9 G3 X W+ T j* f/ N1 K #define S14 22
: t% @0 R* J7 T0 b2 h6 W2 j#define S21 5
; n8 S+ Q; \5 A#define S22 9
, y- ~* ~1 z1 E9 t o3 x1 L4 |3 x+ r #define S23 14
) v N; M/ f8 r- v- B& U#define S24 20
& e `) D- A3 ^+ O" H3 B1 n#define S31 4
1 h1 }. v" Q. E' J #define S32 11
$ l/ \; }) L/ C- D+ m#define S33 16
' U; j c1 }+ \) u3 L, s) K/ x #define S34 23
/ J M) B9 K: | N#define S41 6
V- ^5 V' I! R #define S42 10
b% `2 i; x" s) e) w) c #define S43 15
. L+ i" @% a) b #define S44 21
1 Y; o) m. ?2 v
2 F. s6 a) v$ E' \0 N! ` static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
8 U' i4 }4 N+ S2 V3 {7 k6 w ^, Lstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
P% k7 R: e M, i. e/ o+ [4 M. m2 ? static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
, A6 \( q( H4 ]5 w+ ]+ @! C static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
- i; r- v7 Y) sstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
' |: z1 g | k# ^# S3 Q
) ?# G3 d; v) F5 ~# H1 ^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
& w2 v% R8 t9 B8 h0 I0 l};
- S D% ^1 P5 L
$ f! O! `( h/ R v! k /* F, G, H and I are basic MD5 functions.
*/
+ T: J' ^9 e, d& P* n; b$ c, W #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
) l8 T0 K3 {% F: |7 T$ Y #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
: ^! g8 f2 p. j5 y3 y* j#define H(x, y, z) ((x) ^ (y) ^ (z))
) B' a t, U: h9 S2 y #define I(x, y, z) ((y) ^ ((x) | (~z)))
" J) j* @: }) K- H* V$ m0 L
( ^* ]( y+ `. @+ y$ ^0 h/* ROTATE_LEFT rotates x left n bits.
*/
! S) R" ^: e+ U, Z3 J#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
% w% d% N) _, Z5 D
" N5 c2 E3 I, V m. U* C/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
8 S* o* s Q% H+ J* H, x M5 TRotation is separate from addition to prevent recomputation.
*/
; ]1 {9 a9 k% v. j: k" r* U #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
8 ~2 n3 r) \' ~0 M #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
; I$ ]) j+ c! v$ J+ ]#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
0 K" Z3 C n) u1 y! K2 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); \
}
. w* c: d( k6 L, R; ?
+ ~+ g5 N& T. p8 o/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
+ {& q+ h1 w" L* G0 n9 Z, a# |; ivoid MD5Init (context)
: k$ [2 [, K. E6 d9 z' U+ mMD5_CTX *context; /* context */
# e3 _) A( E( r1 {% _+ Z{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
# V. G4 b5 H1 g*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
1 J: R# H8 Y. ?# }& ^0 Q}
1 z s& ^3 l' j Z+ U& e; g9 e9 r/ V
0 ^+ c; n* V7 h* U& f* c4 J. P* r /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
9 U# R* u3 l2 g( N$ G1 Z void MD5Update (context, input, inputLen)
9 f3 b0 ^; ~5 E- g7 b- i3 j( P3 L3 IMD5_CTX *context; /* context */
0 W; _# g" }6 q1 j unsigned char *input; /* input block */
7 g$ S; C( @9 G6 E0 E% i2 Eunsigned int inputLen; /* length of input block */
# k: T N, U# G7 C6 K{
unsigned int i, index, partLen;
, N2 D Y' l* D( |: t+ d$ D
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
; `$ b% U% e3 {/ I# z& d
/* 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++程序


7 U/ {7 x7 r! m5 h. V) R6 ?
4 T- t! x4 F8 t6 J0 r& [
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-1 23:20 , Processed in 0.538595 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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