中国安防论坛

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

md5加密算法C++程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-26 20:11:20 | 显示全部楼层 |阅读模式
#include "global.h"
9 ~8 w* o* ~# L#include "md5.h"
: Z: }! j0 c5 @3 L }
+ ^/ n2 Z% h( d) w# l# s /* Constants for MD5Transform routine.
*/
+ D" [5 L2 \. q! d) S8 L, G
" w( z/ @# n) t# d
) g( m2 M9 e' g! Y% w" } #define S11 7
" K7 s4 z7 d9 ?- ^" H7 O' Z1 l( X #define S12 12
6 U! m- s' ]5 A w #define S13 17
/ _) d5 H) c, {7 l6 V" _# @0 v #define S14 22
2 v' w4 c: a3 I2 v; B7 Q4 p$ Z #define S21 5
/ {+ S f S0 a3 Y#define S22 9
$ {. F, b1 O1 }#define S23 14
' g) A7 P/ m+ P9 p; P# |, p0 y& J #define S24 20
" f) C; R' U6 g, a7 U- o' J4 K+ C #define S31 4
& u* @1 W# D7 Y/ ^( a9 J! n; } #define S32 11
/ Z' @$ A M* `& y* u#define S33 16
& o- ~" v0 N' Q) u, s" X #define S34 23
0 L/ m/ \3 u4 {& p# W) T4 l #define S41 6
0 t& k: H# P& i#define S42 10
- Z) ?, V P% O$ C8 {#define S43 15
+ a$ S; p( w3 d/ {6 o0 q1 B #define S44 21
7 p: u) F- o8 e) X8 T
3 | k3 m" Z6 p! q static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
8 H% i' ~2 x b: u/ j: C static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
* r0 ?( T8 R4 Z F6 u: t static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
4 J/ ^: W3 i6 H& J static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
0 ?. s2 A* Z" D( gstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
$ \/ ^% }2 x5 }! p' U" V* r
5 ?! U7 M" o6 [' lstatic 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
9 H! L0 V h& d. ?' c};
4 C9 \( O4 ^+ c3 r
3 _, {9 Q2 Q4 ]# q" D3 f7 Y/* F, G, H and I are basic MD5 functions.
*/
$ {' J9 E) X, J, y6 X1 c #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
) }; G1 R5 |4 W0 }6 B9 S: z: B3 [ #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
( K: R1 Z% J+ r+ z" z& Z: Z #define H(x, y, z) ((x) ^ (y) ^ (z))
o0 @5 R- n. ^7 q#define I(x, y, z) ((y) ^ ((x) | (~z)))
" f' w6 u+ {# {# _' e
, q& _% j" ]6 R! l( I/* ROTATE_LEFT rotates x left n bits.
*/
" m/ m0 W5 x3 q4 \#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
4 m" e8 H3 G8 C) G2 \) q0 f
9 l% P% r% ]3 ~' _ t' R9 I$ z/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 S [. O/ M! n9 n0 _, ERotation is separate from addition to prevent recomputation.
*/
3 k% @2 x" p! y #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, ?" w [- O" f; V6 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); \
}
* C' q6 E9 [1 J$ E% N- r: ~* b#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
" P- z: X+ v3 l$ d; G/ s) X, `#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 I6 m) N; r8 j5 o
* S9 K) z: Y: e) o+ b: _' T+ c/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
+ r O* `% e. s) @* _' H7 ^" v+ S3 i* W& V void MD5Init (context)
1 F" v) R# o- J/ L: t- l. k7 eMD5_CTX *context; /* context */
9 v- s5 h; U" Y8 k{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
2 ? l, X1 }" P/ }& N */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
) u& a+ y; y4 E# q! Z! Y }
' g2 v; J! I! Y9 v7 c
# A% u5 {1 A' V" U+ {+ K/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
" T& J- j8 U( n" R5 P. W( R3 xvoid MD5Update (context, input, inputLen)
; F3 H- d R7 `0 W. r" l9 R" F MD5_CTX *context; /* context */
7 c" @$ ]7 |6 \; K6 hunsigned char *input; /* input block */
J6 ~6 w# G& sunsigned int inputLen; /* length of input block */
; u: N1 O5 r/ T! L+ I# x! P' p{
unsigned int i, index, partLen;
0 Z/ m6 {& g, X! @& z
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
4 e. @. d" l; @+ 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++程序


, `1 r0 c9 F$ m6 \0 Z
0 a1 m* Z+ n, v) h8 {
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-19 06:17 , Processed in 0.133952 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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