中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
! e8 Z6 ~6 e* @) C#include "md5.h"
' i6 }1 ?9 Y' O
3 F. Y' q* Z( O6 x( p- c2 \/* Constants for MD5Transform routine.
*/
+ K4 _9 t R+ `
( g2 ]8 R* v, E: W3 R4 j
0 w5 L9 q4 S# N# R/ W C#define S11 7
1 y9 H+ ^# a1 e7 _& M- z/ z0 W8 N1 E #define S12 12
% \2 M: s$ d% V9 Y3 P #define S13 17
8 m: u/ S/ U4 {! {: ?( | #define S14 22
' d" B( `: n0 Q4 K. p! h9 U #define S21 5
. Y) ]) i7 a: N #define S22 9
5 N; L4 o( e4 I* ~4 l4 n#define S23 14
5 c3 f& |2 j! Y0 [$ F) K #define S24 20
- e S$ }$ e/ }#define S31 4
0 F6 Y8 h' O5 ?* ` #define S32 11
6 J0 N; R1 \3 S #define S33 16
) N9 C) W2 v; E) |#define S34 23
( c: n9 q/ C! x1 G! q0 N #define S41 6
! [. ?# o8 i6 |6 Y#define S42 10
, h' B4 X, _8 r3 ^; d- y5 S- x#define S43 15
2 s. K; x% U. T #define S44 21
) ~3 ^( v- |$ F! l9 K
5 \3 K: F8 I% S8 R9 |) Y7 q+ O static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
3 ?, L' K3 `3 d* s: G( y3 M% {static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
) R( D$ E% ~. K: X3 a( e" {% ~- r, D. Q static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
' a( G6 _2 T' ^" _' e2 }static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
- t; }1 H' H5 C+ Ostatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
1 V" V S1 x. @
0 M' D2 g1 Y& t- \8 O; G% S. Sstatic 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
3 Y* {0 }0 y2 |9 C };
8 K/ E! q( D0 k! r3 o
8 D2 T5 v6 _/ v1 v/* F, G, H and I are basic MD5 functions.
*/
, A) H, u$ D( W$ ` #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
3 x) X1 x# F; w! z; z9 }#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
$ E' A: y: I! a; H, L$ l#define H(x, y, z) ((x) ^ (y) ^ (z))
; ]" _( X9 O6 p0 ?1 J6 r+ s #define I(x, y, z) ((y) ^ ((x) | (~z)))
h+ F/ G. \) g- J8 q0 g% f: O/ t
3 @+ t" ~& Y* S# M$ }* j, n3 z2 W/* ROTATE_LEFT rotates x left n bits.
*/
5 L* C5 \3 S1 T" _7 p#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- ^! ?5 |; x2 E2 I! s1 l5 U
. r% P3 c; b- i& f7 l; i j1 C/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
# H) D9 g q5 a" CRotation is separate from addition to prevent recomputation.
*/
\! O$ p+ U& I' Z#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 L! O& z4 K' ]3 l3 c #define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
+ z6 q( h A( |$ F# ~0 U#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
% `% p5 P: O7 U& 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); \
}
3 n8 |0 z. T/ F; w; h
+ B6 I+ B" S/ N5 H6 I! y/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
5 F* t5 [ X6 u- y3 R void MD5Init (context)
5 [& B5 a: p4 ?" }& t, k- v MD5_CTX *context; /* context */
& ^- {* O- P. Y: y {
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
6 T2 ~# a c" M: y1 g*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
5 ?- V8 r9 e O4 H}
) s3 N5 N5 z5 ?. {( R- Z) `
6 |! Y- Q( w8 Z; j/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
7 T- O3 B0 j+ b; \3 y! i void MD5Update (context, input, inputLen)
! Z- s+ y! i; y" UMD5_CTX *context; /* context */
- q* k! n/ c* ?, b$ X. L unsigned char *input; /* input block */
7 n& r& ]0 }3 v) l unsigned int inputLen; /* length of input block */
* a6 `5 @: g6 }6 u. h{
unsigned int i, index, partLen;
+ v6 k# X( w" h p3 G) j4 h
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/ Y0 n6 K% M8 h( C6 x+ r& J
/* 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++程序


, _1 d5 N* L+ _: j* H
m& e8 Z" O) @5 Z& [) ~
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-7-5 18:47 , Processed in 0.055757 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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