开云手机版登录入口

 找回密码
 注册
查看: 5136|回复: 1
打印 上一主题 下一主题

md5加密算法C++程序

[复制链接]

开云手机版登录入口中学生

Rank: 2

积分
147
跳转到指定楼层
1#
发表于 2004-11-26 20:11:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "global.h"
: Y* {0 h, S0 U0 [% ]; b #include "md5.h"
2 ~# N' G9 k% y
) m1 H/ a, }* |8 V' }( C* U/* Constants for MD5Transform routine.
*/
$ ?9 ?3 t3 y" b) B" |; Y# d
e" q7 n( O! K' ?
( [6 D0 w3 q* G5 a4 x ~ #define S11 7
/ w" X; s5 ?) _3 g #define S12 12
7 D: ` o( O: A. K; m: ?#define S13 17
9 j+ C4 Z1 F& R3 q#define S14 22
; ~" a) @$ A6 }( }8 P#define S21 5
* ^/ N5 Y$ i8 y/ r" i4 {( Q0 R#define S22 9
2 h O3 O6 y4 c0 I #define S23 14
! \2 Z, V* P8 U9 | #define S24 20
1 m" \, \, c0 w/ n8 r7 p#define S31 4
0 I7 i0 V* A2 y8 i #define S32 11
9 X. ~. Z/ O. R6 L' M H! j2 D: x5 @ #define S33 16
3 `! n* W; x, f& _( u* m+ H #define S34 23
0 K. t3 } X9 V$ E) a' K #define S41 6
# c7 @( c: A6 Q: Q2 h3 X #define S42 10
1 ]( A- v( _+ r7 m1 @) B #define S43 15
9 x( d* r( m, h" g, Y: x$ Q. y, y #define S44 21
3 Z9 B& Q' S% i* W
# p( P3 a ~# x f static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
2 ?) {& T/ E+ k y! fstatic void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
, V; G( D# }/ B1 q- rstatic void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
D( s8 g9 Y9 P3 D( gstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
) G# g. w3 y+ n+ r5 Q" s( g) q8 o static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
( K8 q* b+ }+ Z$ _3 [9 P
- k8 k2 i3 g+ d8 ~) P 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
6 J1 U* i' M1 l+ S };
) ?" [* D+ q& a5 @0 P. z) I! O
* l' `% h, U# t/* F, G, H and I are basic MD5 functions.
*/
& ^$ y7 C8 K' N; Q3 u) J o& D+ k #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
7 i, Q0 L. O8 e7 e8 P% E# u#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
4 @, L$ n4 G: B/ G6 K1 |. s9 T#define H(x, y, z) ((x) ^ (y) ^ (z))
7 |! J1 n- `0 s6 W5 v* d6 T6 t #define I(x, y, z) ((y) ^ ((x) | (~z)))
) a/ U9 Y0 V/ ^6 A% M
/ y/ |# h9 y. d- h/* ROTATE_LEFT rotates x left n bits.
*/
( @/ W ^$ j$ A i* I #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
# [4 O8 h M+ w5 Y( m
% \( S& m- S8 q" a5 j /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
7 k+ [: g7 X. R& d Rotation is separate from addition to prevent recomputation.
*/
9 q( C7 W8 m l; M' D' [ #define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
4 }9 F* f; w3 _9 B) l) P! n+ t% ^( i \ #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% p/ V$ d F( X0 O( R7 [5 U' A0 x#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
9 S) K# F/ p9 {#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
, z3 X0 ~+ Y. B4 n
. [) z, t2 a* ]+ v) f /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
& `5 S+ I5 j& S% d' e5 }- X5 {5 Tvoid MD5Init (context)
, ?; k$ y2 @9 W4 BMD5_CTX *context; /* context */
2 Y; x; O5 X+ f/ W- t" L{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
9 \* p! r: v3 l v. n" _ G */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
6 T! X0 I+ @, B/ K: N2 S}
- H- A5 T5 [1 ~. l9 ^
! ?% ]. W' f2 n9 J /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
# s# Z8 Q+ `" d" [. D# G void MD5Update (context, input, inputLen)
1 Q& C0 a) J+ n u- Y% d8 tMD5_CTX *context; /* context */
3 K x; a7 m2 C6 I" ]$ x' o( e$ hunsigned char *input; /* input block */
* H* Q" O* Y5 Q8 A( r4 [unsigned int inputLen; /* length of input block */
( N6 O) a( ]4 O5 l) f+ m{
unsigned int i, index, partLen;
) G& J( x; ]0 w% A
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
! C: p, \% A3 u# @2 z) u
/* Update number of bits */
if ((context->count[0] += ((UINT4)inputLen << 3))
&
不在競爭中變坏,就在沉默中變態

开云手机版登录入口知名大师

探花

Rank: 7Rank: 7Rank: 7

积分
1057
QQ
2#
发表于 2004-11-26 20:22:48 | 只看该作者

md5加密算法C++程序


A9 B- i! b% t9 c. p P
, e5 `+ d, \ t5 \1 [9 \# S' E/ Y) e
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

安豆网|Archiver|手机版|开云手机版登录入口 ( 粤ICP备09063021号 )

GMT+8, 2025-11-4 13:32 , Processed in 0.065666 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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