中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
W9 _ _8 X2 d6 [#include "md5.h"
. u/ Q" _* c% A0 T$ W, h2 |
5 ` P* R5 }2 }/ k /* Constants for MD5Transform routine.
*/
+ k2 X. b; E* K* @- B
, T; j% ~* o1 Q7 e
; ]( T" X7 _ R5 d) g#define S11 7
5 V& u% B) D4 |( Y #define S12 12
0 V7 W% N$ |7 E #define S13 17
( A+ q7 y6 f1 T% P2 i" b+ O#define S14 22
5 a& Q( M4 Q4 y. x: g#define S21 5
: w6 S$ D2 v! G/ v9 H1 Q7 o# a- |& L0 o#define S22 9
" z* d8 W. T" a5 H. x+ Q1 t #define S23 14
9 p' y d. `7 N% _# _#define S24 20
8 P6 o V6 e' ^" _( i1 O#define S31 4
+ J# Q* [/ N6 ]2 a3 U#define S32 11
( l I$ L+ \% [& n8 L3 D #define S33 16
! k% r+ l) `+ k( i) v5 \' f #define S34 23
4 Q! k& i* _9 p& T1 Y#define S41 6
2 h" v8 g$ d+ h, l #define S42 10
7 K* G/ _3 v) K. b' h#define S43 15
' F( n4 ]$ H a( o$ j8 y' V3 i: ~ #define S44 21
& `7 R7 O6 `; I$ h
& T7 h8 I2 @- `6 ?! e; X static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
7 M- I+ o6 Y% s static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
; \( S1 G5 u3 d( b2 gstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
9 w. M3 W( Q. \" I, N) m' r static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
" J: K6 G& {: T0 i2 n& [ static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
" U7 l" @9 _; m& z5 s+ ]
' K X, T* T; ?$ B8 f( N& 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
& y8 l% Z+ j4 B& B) B" d3 B };
, ~7 G9 n# E: a3 T( ]
0 V; K w; ]0 ~/* F, G, H and I are basic MD5 functions.
*/
! x8 j4 b5 X7 Z1 ~. a& S) U7 o #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
; l+ b# s2 q* t+ h #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
% a1 e- {; _4 W #define H(x, y, z) ((x) ^ (y) ^ (z))
" N/ F; [8 c; x #define I(x, y, z) ((y) ^ ((x) | (~z)))
/ N! Q+ x1 x4 U0 a8 x- ^+ m6 d4 x
0 y0 i* j) ?( R) i2 b9 B /* ROTATE_LEFT rotates x left n bits.
*/
) Q+ o2 x, ]$ @0 n$ y- T#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
" d+ D- `1 i' V- C& W; c" r
p4 G/ E% m! S" g. g /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
3 Z/ u& j s' P u$ S5 CRotation is separate from addition to prevent recomputation.
*/
: a0 H9 {2 C! ]$ J #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
" b! d# B! I$ F/ w" ]. 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); \
}
1 Q# I3 q' R0 T& j9 D1 ~ #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
' y+ W# P6 h7 D- z1 a #define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
) e9 n5 B$ _; K6 t3 o6 l
8 m- q" [6 f1 F+ @$ i /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
& ^! P$ T8 Q2 l( q void MD5Init (context)
# }1 ]7 D2 z( E+ \7 S- l; n MD5_CTX *context; /* context */
: k: e K( A1 g6 Z5 v{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
: v2 G% @: a/ x4 P+ `( n */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
/ r' L6 v( f: l" W) i% H+ K6 j }
& D9 E) c } O$ d! @2 g' |
( W8 h8 l9 C3 ]1 N5 w% `% T/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
! E7 |* N5 w% h/ \5 z$ \' Evoid MD5Update (context, input, inputLen)
0 U- Y& }- b6 E0 v. [( Q MD5_CTX *context; /* context */
( y# W( T+ A( X9 Munsigned char *input; /* input block */
. i( L% A* v5 K5 i7 Z7 ]unsigned int inputLen; /* length of input block */
; A* @0 G$ k* j8 r5 r: c{
unsigned int i, index, partLen;
0 r+ p- V+ e! M, w9 F" Y
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ T3 A3 O1 z5 W- E3 |) E
/* 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 p y0 x. {* A6 t
2 l J4 h) W( y
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-28 07:50 , Processed in 0.064574 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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