中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
7 g3 P( B9 b# H" }# q: R9 b#include "md5.h"
' w) _! x0 X# C
' A/ L& p1 ?! w6 }8 h/* Constants for MD5Transform routine.
*/
' s7 {1 r, y- M. a L
8 |( i1 k) h1 g7 ?' H( E
0 c8 Z. E, i, V+ l* K" { O#define S11 7
) @; j9 d* T. p q& b9 S#define S12 12
; B9 I0 o6 }% [: ]# d #define S13 17
; d( p1 F# j4 I; s9 x#define S14 22
3 Q8 C$ D Y1 s" J3 |#define S21 5
' {1 \6 ?6 r6 L9 p6 ]- F7 Q #define S22 9
8 {6 t! c9 X( { [ H4 O8 \#define S23 14
1 C2 F$ s/ l8 H#define S24 20
# b/ r% U* A/ A2 C* ~ #define S31 4
: p5 j& }# f" X #define S32 11
" Q. z" I& _" t, y3 ^#define S33 16
" ] n5 D- q+ [#define S34 23
1 L0 D* v, W( q% f #define S41 6
" |# ^ V: }3 v# p#define S42 10
8 x+ Z* A4 W* X#define S43 15
2 e3 b. y% p( O#define S44 21
2 j0 S9 M1 ]9 f. z
& ]; @/ J: \+ D! lstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 u! D9 c+ W d# Lstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
2 U& t8 _- r# B. q( q% g- @2 vstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
4 \: E0 x% h1 F+ s+ Y5 j4 j2 v static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
9 k9 I2 ~# ~/ K3 U1 C; q2 u: Zstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
' r8 z( z% h& H$ W
f7 K$ o" s- d$ d6 Q2 n7 O 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
" q/ c1 C5 c3 c; C; o };
, |1 y6 @" U) k. \& Z
6 w, e& ~- K( i7 O( U /* F, G, H and I are basic MD5 functions.
*/
& t- e9 V" r3 y8 {& \% A #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
% A3 W; n( c& Y* I#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+ q0 D; p+ x `6 R; B- \4 Y# } #define H(x, y, z) ((x) ^ (y) ^ (z))
9 D2 n6 c8 d% ^ #define I(x, y, z) ((y) ^ ((x) | (~z)))
, W( _+ ]. S+ ~7 x8 e2 c% J4 j
& F; P% K4 G" n/* ROTATE_LEFT rotates x left n bits.
*/
% ?1 X. `" S) [) ]2 Z7 v7 D8 Z #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
7 B( D, {. c0 ^9 ?( x. k: X7 t
# X$ ]1 p; y# ^: M4 g( s/ S- O /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
3 }7 A4 ^" E+ e4 }/ x9 f% wRotation is separate from addition to prevent recomputation.
*/
7 b9 B9 t) R# |5 k6 t: }. H- ` #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 Q" A1 C& Y" K. ^; h9 f#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
" c" z4 P! {, r2 G0 i" h( ? #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
1 R9 R0 i, } k7 d#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 C% s2 ?% ^7 N1 C7 y3 z5 g
' G7 N* h$ t& Z3 U7 c/ e /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
' @$ H1 v, P u2 O8 \ void MD5Init (context)
& W% ^2 U5 k4 p$ x2 o+ n5 VMD5_CTX *context; /* context */
* F4 E, z, f2 y$ L2 K8 K. Z, |3 _{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
( V0 _ a7 B$ Q6 I0 R* S9 A J1 K */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
' o4 W6 f2 Z: a }
( @& j4 E" k: L, I7 [. _
5 ?% @3 W6 D, S8 R: \ @ /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
) @& u. ^" L" g. ? void MD5Update (context, input, inputLen)
8 c( \0 `4 e/ D3 y6 t O( {& w MD5_CTX *context; /* context */
! s7 L3 m& P" g0 V* P& z2 K# dunsigned char *input; /* input block */
" e- ?, H2 ~# k9 o3 m6 l1 I unsigned int inputLen; /* length of input block */
% s9 y# w8 N: d& } ~6 ~+ J {
unsigned int i, index, partLen;
/ u1 i7 J( L) F
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
* l* e9 E* ^: j% q4 @/ [
/* 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++程序


% V/ S9 A& f+ O
+ C& |' d( |2 u" J' M; \ w
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-19 07:17 , Processed in 0.054829 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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