开云手机版登录入口

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

md5加密算法C++程序

[复制链接]

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

Rank: 2

积分
147
跳转到指定楼层
1#
发表于 2004-11-26 20:11:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "global.h"
7 s* k2 z$ ?7 Y+ m( H1 n4 G* u) [9 h#include "md5.h"
5 [7 F$ X- H; z3 L
9 W. f# }1 o6 ]! [8 J, r* l, P /* Constants for MD5Transform routine.
*/
" F7 F+ l( D- V9 f% \
I& l7 Z- g% e3 O( E. m A5 E9 q
( ?8 |9 Q5 \0 Q4 _4 P1 ]#define S11 7
9 u0 }; T' N) ?! R ?#define S12 12
+ y) f* J, J! o. U) y#define S13 17
0 U$ w2 w- Q1 c #define S14 22
2 l. M' E; A, c: D#define S21 5
" @& T) ^: i0 b #define S22 9
1 u2 Q4 B' t3 N #define S23 14
: k9 B$ \6 u+ D) f#define S24 20
" s M2 K0 f+ L) k#define S31 4
- \) [. i% ?! E# v% c3 m% h, ~#define S32 11
6 j' `' D4 {7 l: n4 o# [! y) A#define S33 16
' f. d* x/ v7 M& ^ #define S34 23
# @$ d% F: n1 k& {#define S41 6
+ w: g- e# I) l9 `2 {' g9 S #define S42 10
% m% k+ [8 @5 U#define S43 15
. C& Q/ m* l) z \#define S44 21
/ h& I D$ y" d$ j0 m/ A" Y( |# ]
6 n* m1 S" d+ r. I ^8 pstatic void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
; e, w4 c$ c7 } D& c static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
) D+ Z* w& g" S5 q0 j. [static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
3 U0 d: G/ o3 P* R, wstatic void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
7 n- z: P* j7 A& P) Kstatic void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
( L, `: s2 A# u" U3 n
* n" h, \2 o5 V: 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
) z3 g& }/ g2 w$ \};
, W5 y' ~3 \' ^/ ^ E' b' |, [
- F* ^+ v) Q' \( L) w" @- V/ N /* F, G, H and I are basic MD5 functions.
*/
" b3 t' `6 Z! f5 T #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
, ]- Z3 {5 X0 T #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
* Z% O9 P) q2 U9 _#define H(x, y, z) ((x) ^ (y) ^ (z))
: t+ k5 ^4 G W* i! U& @ #define I(x, y, z) ((y) ^ ((x) | (~z)))
1 O: Q5 {6 v4 t
* s; J) A+ s3 O' B: y /* ROTATE_LEFT rotates x left n bits.
*/
3 X- \; o/ ]' M5 ~7 p* J& @ #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
# B( |7 V) H8 ~* A: k; ?
) S+ {# y8 E d# C; W/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
2 [' v' Z3 I3 V4 u! ?: [. DRotation is separate from addition to prevent recomputation.
*/
0 ?6 n" k8 W; x D4 n A" [% [/ O#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
$ O3 n: w3 z% U c3 ~8 p7 T: H2 M#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; D, P" w. f5 A' n s #define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
8 d. k2 [3 p% y9 O& N4 N#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
6 t0 ^* a1 w1 G0 M" u
3 ~1 K% a( Q& @, X /* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
; w/ d. \" l. J& v$ Svoid MD5Init (context)
5 U5 ?) j. t0 H6 ~4 S MD5_CTX *context; /* context */
% C4 v- w6 Z+ g- ^) m0 A9 M X" v{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
# a' z/ Z4 E5 C" L7 O0 v; Z. j */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
# R w, b% }9 }( D5 k+ c# x$ E}
* F3 {8 g2 J' F* |6 g" a% h& l
3 Q( i7 f3 C; j! W) ?( z /* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
# x/ z- S8 A/ Y& F. z+ Kvoid MD5Update (context, input, inputLen)
2 l3 q. G( V9 y7 ^0 Z! }% ?MD5_CTX *context; /* context */
0 j+ h7 t4 y8 [7 I, E/ ]6 G, Z# n- Uunsigned char *input; /* input block */
$ c8 [/ e/ _3 V! ]# t4 @1 Xunsigned int inputLen; /* length of input block */
& q8 N" J. i) s3 O% |) N/ e{
unsigned int i, index, partLen;
5 m& t- x5 q' p: S
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
: W- X9 f. F, `, V7 \0 t2 c
/* 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++程序


) {- G" I. n9 ^; }
. E2 G+ G; I( U2 @
guoyun786@sohu.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-2 03:02 , Processed in 0.100601 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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